Questions tagged [variable-templates]

Use this tag for anything related to C++14 variable templates.

Variable templates are a feature of C++ as of C++14. They allow variables to be declared as templates, just like functions and classes:

template<class T>
constexpr T pi = T(3.1415926535897932385);

template<class T>
    T circular_area(T r) {
    return pi<T> * r * r;
}
68 questions
0
votes
0 answers

Trying to understand variable templates and template aliases for proper usage

I had previously asked these two questions: Auto Type Deduction Static & Non Static Member Functions My question pertains to the class provided in the first question which is my Signal class. The idea that I'm trying to convey within the class is…
0
votes
2 answers

Multiple variable template specializations with std::enable_if

I'm trying to concisely define a variable template with these effective values: // (template constexpr T EXP = std::numeric_limits::max_exponent / 2;) // float and double scalar definitions: const double huge = std::scalbn(1,…
ZachB
  • 13,051
  • 4
  • 61
  • 89
0
votes
1 answer

Variadic Variable Template specialization with SFINAE

I've been trying out the new(ish) C++14 variable template features, and ran into this curious error during compilation (g++ 6.3.0, but also tested using 8.1.0) templated_variables.cpp:32:19: error: wrong number of template arguments (1, should be at…
Tyg13
  • 321
  • 2
  • 10
0
votes
0 answers

Any specific reason for variable templates in the standard library be inline?

C++17 introduced various helper variable templates, e.g., template< class T, class U > inline constexpr bool is_same_v = is_same::value; template< class T > inline constexpr bool is_aggregate_v = is_aggregate::value; They are all marked…
Lingxi
  • 14,579
  • 2
  • 37
  • 93
0
votes
1 answer

Can variable templates infer type?

c++14 introduced variable templates so I can do: template const auto PI = std::acos(static_cast(-1)); Now, when using this variable can the type be deduced? For example: const auto TWO_PI = 2.0F * PI; Here I would expect PI
Jonathan Mee
  • 37,899
  • 23
  • 129
  • 288
0
votes
2 answers

a surprising value about lambda and cin.get

environment: vs2013 rc5 / vs2017; project: win32 console application; representation:compile and run a little while,then interrupt and watch variable "task_"; if "add_task(&Test::print, &t, str, 10)" in func main, the "task_" is correct…
fredirty2017
  • 103
  • 11
0
votes
1 answer

Can a variable template be mutated?

Today, someone presented me with code of the following form: #include namespace example { template T variable_template = T(42); } int main() { example::variable_template = 10; std::cout <<…
OMGtechy
  • 7,935
  • 8
  • 48
  • 83
0
votes
0 answers

Multiple defined linker error for getting static member variable template

When I have a class that can be boiled down to something like this: // test.hpp class Test{ public: template static T value; }; template Test::value = {}; I can use this class when I only look up an instantiated value in…
val
  • 729
  • 6
  • 19
1 2 3 4
5