[mlpack] Aliasing to object with templated type and size
Ryan Curtin
ryan at ratml.org
Thu Sep 26 22:05:04 EDT 2019
On Mon, Sep 02, 2019 at 01:45:54PM -0700, Joe Dinius wrote:
> Ryan's really helped me out so far, so I'm hoping he can do the same for
> this simple issue I'm having.
>
> I'd like to be able to allocate my own fixed size vector-type using
> aliasing. The following code works well for this:
>
> template<size_T N>
> using Vector = typename arma::colvec::fixed<N>;
>
> Additionally, it would be really handy If I could add the *type* to the
> template definition as well; something like this:
>
> template<typename T, size_T N>
> using Vector = typename arma::Col<T>::fixed<N>;
>
> However, this *does not* work; it fails to compile. This seems more an
> issue with how I am abusing the 11-standard and not an issue with
> armadillo, but I am hoping that someone on this list can shed some light on
> what I am doing wrong here: how can I achieve the desired design pattern
> "Vector<double, N>" is an armadillo vector of doubles of fixed size N.
Hey Joe,
To solve this issue you need to use the ::template operator. (Or, at
least, I was able to solve it this way.)
template<typename T, size_t N>
using Vector = typename arma::Col<T>::template fixed<N>;
More information on this headachey part of C++ here:
https://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords
Hope this helps!
Ryan
--
Ryan Curtin | "No... not without incident."
ryan at ratml.org | - John Preston
More information about the mlpack
mailing list