CPP Template - yszheda/wiki GitHub Wiki
-
https://xenakios.wordpress.com/2014/01/16/c11-the-three-dots-that-is-variadic-templates-part/
-
http://stackoverflow.com/questions/1657883/variable-number-of-arguments-in-c
-
http://stackoverflow.com/questions/39792417/what-does-this-three-dots-means-in-c
-
[!]https://monoinfinito.wordpress.com/category/programming/c/c0x/
- http://stackoverflow.com/questions/16337459/undefined-number-of-arguments-in-c#16337614
- http://stackoverflow.com/questions/20901811/function-with-three-dots-argument
- https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern
- What is the curiously recurring template pattern (CRTP)?
- Curiously Recurring Template Pattern (CRTP), AutoLists and C++
- https://stackoverflow.com/questions/12726954/how-can-i-partially-specialize-a-class-template-for-all-enums
- https://stackoverflow.com/questions/1619993/template-specialization-for-enum
- Template SFINAE & type-traits
- https://stackoverflow.com/questions/1528374/how-can-i-extend-a-lexical-cast-to-support-enumerated-types/1528436#1528436
- https://stackoverflow.com/questions/4238710/specializing-template-for-enum
- https://stackoverflow.com/questions/4543720/is-it-possible-to-specialize-a-template-using-a-member-enum
- https://stackoverflow.com/questions/22721201/specializations-only-for-c-template-function-with-enum-non-type-template-param
-
http://www.enseignement.polytechnique.fr/informatique/INF478/docs/Cpp/en/cpp/types/enable_if.html
-
(Partially) specializing a non-type template parameter of dependent type
-
Check if a template parameter is some type of chrono::duration
template<class T>
struct is_duration : std::false_type {};
template<class Rep, class Period>
struct is_duration<std::chrono::duration<Rep, Period>> : std::true_type {};-
boost::enable_if_c error: is not a valid type for a template non-type parameter
-
How to use std::enable_if with a condition which itself depends on another condition?
-
Best way to handle multiple conditions for conditional compilation
-
https://en.wikibooks.org/wiki/More_C++_Idioms/Member_Detector
-
How to detect whether there is a specific member variable in class?
#include <type_traits>
template <typename T, typename = int>
struct HasX : std::false_type { };
template <typename T>
struct HasX <T, decltype((void) T::x, 0)> : std::true_type { };template<typename T> struct HasX {
struct Fallback { int x; }; // introduce member name "x"
struct Derived : T, Fallback { };
template<typename C, C> struct ChT;
template<typename C> static char (&f(ChT<int Fallback::*, &C::x>*))[1];
template<typename C> static char (&f(...))[2];
static bool const value = sizeof(f<Derived>(0)) == 2;
};
struct A { int x; };
struct B { int X; };
int main() {
std::cout << HasX<A>::value << std::endl; // 1
std::cout << HasX<B>::value << std::endl; // 0
}// C++20
bool has_x(const auto &obj) {
if constexpr (requires {obj.x;}) {
return true;
} else
return false;
}class foo
{ int x; };
struct bar
{ };
struct check_x_helper
{ int x; };
template <typename T>
struct check_x : public T, check_x_helper
{
template <typename U = check_x, typename = decltype(U::x)>
static constexpr std::false_type check (int);
static constexpr std::true_type check (long);
using type = decltype(check(0));
static constexpr auto value = type::value;
};namespace detail {
struct P {typedef int member;};
template <typename U>
struct test_for_member : U, P
{
template <typename T=test_for_member, typename = typename T::member>
static std::false_type test(int);
static std::true_type test(float);
};
}
template <typename T>
using test_for_member =
std::integral_constant<bool, decltype(detail::test_for_member<T>::test(0)){}>;