rexylib/include/rexy/traits.hpp
2020-09-19 10:42:45 -07:00

58 lines
1.8 KiB
C++

/**
This file is a part of rexy's general purpose library
Copyright (C) 2020 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef REXY_TRAITS_HPP
#define REXY_TRAITS_HPP
#include <type_traits> //is_same, decay, integral_constant, declval
namespace rexy{
template<class T, class U>
struct is_type{
static std::true_type check(U*);
static std::false_type check(...);
static constexpr bool value = std::is_same<std::true_type,decltype(check(std::declval<std::decay_t<T>*>()))>::value;
};
template<class T, template<class...> class U>
struct is_template_type_helper{
static constexpr bool value = false;
};
template<template<class...> class U, class... Args>
struct is_template_type_helper<U<Args...>,U>{
static constexpr bool value = true;
};
template<class T, template<class...> class U>
struct is_template_type : public is_template_type_helper<std::decay_t<T>,U>{};
template<class T, template<class...> class Tmpl>
struct is_template_derived_type{
template<class... Args>
static std::true_type test(Tmpl<Args...>*);
static std::false_type test(void*);
static constexpr bool value = std::is_same<std::true_type,decltype(test(static_cast<std::decay_t<T>*>(nullptr)))>::value;
};
}
#endif