template-instantiation

Is “if constexpr” useful outside of templates?

时光怂恿深爱的人放手 提交于 2021-02-18 22:51:52
问题 I'm trying to understand if constexpr fully. I understand, that if if constexpr(expr) used in a template, and expr is dependent on a template parameter, then during instantiation, only one of the then / else branches will be instantiated, the other will be discarded. I've got two questions: Is it true, that if expr is not dependent on a template parameter, then no branches of if constexpr(expr) will be discarded? If yes, where does the standard say so? I don't see where the standard has the

Can I make my compiler use fast-math on a per-function basis?

点点圈 提交于 2020-05-13 04:19:58
问题 Suppose I have template <bool UsesFastMath> void foo(float* data, size_t length); and I want to compile one instantiation with -ffast-math ( --use-fast-math for nvcc), and the other instantiation without it. This can be achieved by instantiating each of the variants in a separate translation unit, and compiling each of them with a different command-line - with and without the switch. My question is whether it's possible to indicate to popular compilers (*) to apply or not apply -ffast-math

Can I make my compiler use fast-math on a per-function basis?

与世无争的帅哥 提交于 2020-05-13 04:13:09
问题 Suppose I have template <bool UsesFastMath> void foo(float* data, size_t length); and I want to compile one instantiation with -ffast-math ( --use-fast-math for nvcc), and the other instantiation without it. This can be achieved by instantiating each of the variants in a separate translation unit, and compiling each of them with a different command-line - with and without the switch. My question is whether it's possible to indicate to popular compilers (*) to apply or not apply -ffast-math

Can I make my compiler use fast-math on a per-function basis?

大憨熊 提交于 2020-05-13 04:11:49
问题 Suppose I have template <bool UsesFastMath> void foo(float* data, size_t length); and I want to compile one instantiation with -ffast-math ( --use-fast-math for nvcc), and the other instantiation without it. This can be achieved by instantiating each of the variants in a separate translation unit, and compiling each of them with a different command-line - with and without the switch. My question is whether it's possible to indicate to popular compilers (*) to apply or not apply -ffast-math

Is there a trick to explicitely instantiate deep template classes?

孤者浪人 提交于 2020-01-25 04:16:20
问题 I have a problem: I want to explicitely instantiate a class like Datatype in: using Layout = some::namespaces::Meat_Layout<Some,Parameters>; using Datatype = other::namespaces::Meta_Datatype<Layout>; For explicit instantiation I need to use elaborated type specifiers. Which do not allow the usage of typedefs. Therefor I can not write: template class Datatype; But I have to write: template class some::namespaces::Meta_Datatype<other::namespaces::Meat_Layout<Some,Parameters>>; If there are any

Is a specialization implicitly instantiated if it has already been implicitly instantiated?

谁说我不能喝 提交于 2019-12-10 02:02:31
问题 The question in the title is clear enough. To be more specific, consider the following example: #include <type_traits> template <typename T> struct is_complete_helper { template <typename U> static auto test(U*) -> std::integral_constant<bool, sizeof(U) == sizeof(U)>; static auto test(...) -> std::false_type; using type = decltype(test((T*)0)); }; template <typename T> struct is_complete : is_complete_helper<T>::type {}; // The above is an implementation of is_complete from https:/

Expecting different types depending of point of instantiation

三世轮回 提交于 2019-12-09 13:48:21
问题 I expect the following to be ill formed NDR, but it seems not :-( #include <type_traits> template <typename T, typename Enabler = void> struct is_complete : std::false_type {}; template <typename T> struct is_complete<T, std::void_t<decltype(sizeof(T) != 0)>> : std::true_type {}; class X; static_assert(!is_complete<X>::type{}); // incomplete type class X {}; static_assert(!is_complete<X>::type{}); // complete, but already instantiated Demo Note : Assuming sizeof(T) != 0 is valid for

Force template instantiation via typedef : success at g++ , fail at Visual C++

≡放荡痞女 提交于 2019-12-08 15:32:01
问题 I want to force template instantiation. The below code works (print 1 ) at g++ ( http://coliru.stacked-crooked.com/a/33986d0e0d320ad4 ). However, it prints wrong result ( 0 ) at Visual C++ ( https://rextester.com/WGQG68063 ). #include <iostream> #include <string> template <int& T>struct NonTypeParameter { }; //internal implementation int lala=0; template <typename T> struct Holder{ static int init; }; template <typename T> int Holder<T>::init = lala++; //tool for user template <typename T>

Is a specialization implicitly instantiated if it has already been implicitly instantiated?

随声附和 提交于 2019-12-05 01:27:16
The question in the title is clear enough. To be more specific, consider the following example: #include <type_traits> template <typename T> struct is_complete_helper { template <typename U> static auto test(U*) -> std::integral_constant<bool, sizeof(U) == sizeof(U)>; static auto test(...) -> std::false_type; using type = decltype(test((T*)0)); }; template <typename T> struct is_complete : is_complete_helper<T>::type {}; // The above is an implementation of is_complete from https://stackoverflow.com/a/21121104/5376789 template<class T> class X; static_assert(!is_complete<X<char>>::type{}); //