Skip to content

Instantly share code, notes, and snippets.

@outro56
Created February 2, 2019 16:56
Show Gist options
  • Select an option

  • Save outro56/3308d886026b21c62a3c65fcbe099f06 to your computer and use it in GitHub Desktop.

Select an option

Save outro56/3308d886026b21c62a3c65fcbe099f06 to your computer and use it in GitHub Desktop.

Revisions

  1. outro56 created this gist Feb 2, 2019.
    5 changes: 5 additions & 0 deletions is_assignable.hpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    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>;
    13 changes: 13 additions & 0 deletions is_detected.hpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,13 @@
    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;