# Variable templates (C++17) ___ ## Why? Eg. different precision ```cpp template constexpr T pi = T(3.1415926535897932385L); template T circular_area(T r) { return pi * r * r; } ``` But it is really rarely used. ___ ## Specialization example #2 - field values Remember this code? ```c++ [] #include template // primary template struct is_int { static constexpr bool value = false; }; template<> // explicit specialization for T = int struct is_int { static constexpr bool value = true; }; template constexpr bool is_int_v = is_int::value; int main() { std::cout << is_int_v << '\n'; // prints 0 (false) std::cout << is_int_v << '\n'; // prints 1 (true) return 0; } ``` We mainly use template variables as helpers to class template field values. ___ Check out [`type_traits` on cppreference.com](https://en.cppreference.com/w/cpp/header/type_traits) Every trait has a corresponding helper variable template. ___ ## Exercise Write a variable template `is_int_key_v`. It should return a value of the `is_int_key` field in a given template type.