M
mathieu
Hi there,
I was recently help for an issue with the following code:
template <typename T, unsigned int N>
struct Functor
{
T values[N];
};
#include <algorithm>
template <typename T, unsigned int N>
Functor<T,N> makeFunctor(T const (&a)[N])
{
Functor<T,N> f;
std::copy(a, a + N, f.values);
return f;
}
int main()
{
const double v[] = {0, 1, 4, 9, 16, 25, 36 };
const unsigned int N = sizeof(v) / sizeof(v[0]);
Functor<double,N> f = makeFunctor(v);
return 0;
}
Is this completely equivalent to doing (*). or am I garantee that
template will be inlined (without explicit inline keyword).
Thanks
-Mathieu
(*)
#include <algorithm> // std::copy
template <typename T, unsigned int N>
struct Functor
{
Functor(T const (&a)[N])
{
std::copy(a, a+N, values);
}
T values[N];
};
int main()
{
const double v[] = {0, 1, 4, 9, 16, 25, 36 };
const unsigned int N = sizeof(v) / sizeof(*v);
Functor<double,N> f = v;
return 0;
}
I was recently help for an issue with the following code:
template <typename T, unsigned int N>
struct Functor
{
T values[N];
};
#include <algorithm>
template <typename T, unsigned int N>
Functor<T,N> makeFunctor(T const (&a)[N])
{
Functor<T,N> f;
std::copy(a, a + N, f.values);
return f;
}
int main()
{
const double v[] = {0, 1, 4, 9, 16, 25, 36 };
const unsigned int N = sizeof(v) / sizeof(v[0]);
Functor<double,N> f = makeFunctor(v);
return 0;
}
Is this completely equivalent to doing (*). or am I garantee that
template will be inlined (without explicit inline keyword).
Thanks
-Mathieu
(*)
#include <algorithm> // std::copy
template <typename T, unsigned int N>
struct Functor
{
Functor(T const (&a)[N])
{
std::copy(a, a+N, values);
}
T values[N];
};
int main()
{
const double v[] = {0, 1, 4, 9, 16, 25, 36 };
const unsigned int N = sizeof(v) / sizeof(*v);
Functor<double,N> f = v;
return 0;
}