Created
February 2, 2019 16:56
-
-
Save outro56/3308d886026b21c62a3c65fcbe099f06 to your computer and use it in GitHub Desktop.
C++ template meta programming - https://www.fluentcpp.com/2017/06/02/write-template-metaprogramming-expressively/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename T, typename U> | |
using assign_expression = decltype(std::declval<T&>() = std::declval<U&>()); | |
template<typename T, typename U> | |
constexpr bool is_assignable = is_detected<assign_expression, T, U>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
template<typename...> | |
using try_to_instantiate = void; | |
using disregard_this = void; | |
template<template<typename...> class Expression, typename Attempt, typename... Ts> | |
struct is_detected_impl : std::false_type{}; | |
template<template<typename...> class Expression, typename... Ts> | |
struct is_detected_impl<Expression, try_to_instantiate<Expression<Ts...>>, Ts...> : std::true_type{}; | |
template<template<typename...> class Expression, typename... Ts> | |
constexpr bool is_detected = is_detected_impl<Expression, disregard_this, Ts...>::value; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment