forked from boostorg/type_traits
Implement detection idiom toolkit
This commit is contained in:
1 parent
5d5c651ea6
commit
35c105501b
21 files changed
+662
-2
No files matched your search
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Copyright 2017 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||
#ifdef TEST_STD
|
||||
#include <type_traits>
|
||||
#else
|
||||
#include <boost/type_traits/detected_or.hpp>
|
||||
#endif
|
||||
#include "check_integral_constant.hpp"
|
||||
#include "check_type.hpp"
|
||||
|
||||
#define CHECK_FALSE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, false)
|
||||
#define CHECK_TRUE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, true)
|
||||
|
||||
template<class T>
|
||||
using type_t = typename T::type;
|
||||
|
||||
struct has_type {
|
||||
using type = char;
|
||||
};
|
||||
|
||||
struct no_type { };
|
||||
|
||||
TT_TEST_BEGIN(detected_or)
|
||||
|
||||
CHECK_FALSE((::tt::detected_or<bool, type_t, int>::value_t::value));
|
||||
CHECK_TRUE((::tt::detected_or<bool, type_t, has_type>::value_t::value));
|
||||
CHECK_FALSE((::tt::detected_or<bool, type_t, no_type>::value_t::value));
|
||||
BOOST_CHECK_TYPE4(::tt::detected_or<bool, type_t, int>::type, bool);
|
||||
BOOST_CHECK_TYPE4(::tt::detected_or<bool, type_t, has_type>::type, char);
|
||||
BOOST_CHECK_TYPE4(::tt::detected_or<bool, type_t, no_type>::type, bool);
|
||||
BOOST_CHECK_TYPE4(::tt::detected_or_t<bool, type_t, int>, bool);
|
||||
BOOST_CHECK_TYPE4(::tt::detected_or_t<bool, type_t, has_type>, char);
|
||||
BOOST_CHECK_TYPE4(::tt::detected_or_t<bool, type_t, no_type>, bool);
|
||||
|
||||
TT_TEST_END
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
Copyright 2017 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||
#ifdef TEST_STD
|
||||
#include <type_traits>
|
||||
#else
|
||||
#include <boost/type_traits/detected.hpp>
|
||||
#endif
|
||||
#include "check_integral_constant.hpp"
|
||||
#include "check_type.hpp"
|
||||
|
||||
#define CHECK_FALSE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, false)
|
||||
#define CHECK_TRUE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, true)
|
||||
|
||||
template<class T>
|
||||
using type_t = typename T::type;
|
||||
|
||||
struct has_type {
|
||||
using type = char;
|
||||
};
|
||||
|
||||
struct no_type { };
|
||||
|
||||
TT_TEST_BEGIN(detected)
|
||||
|
||||
BOOST_CHECK_TYPE3(::tt::detected_t<type_t, int>, boost::nonesuch);
|
||||
BOOST_CHECK_TYPE3(::tt::detected_t<type_t, has_type>, char);
|
||||
BOOST_CHECK_TYPE3(::tt::detected_t<type_t, no_type>, boost::nonesuch);
|
||||
|
||||
TT_TEST_END
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2017-2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||
#ifdef TEST_STD
|
||||
#include <type_traits>
|
||||
#else
|
||||
#include <boost/type_traits/is_detected_convertible.hpp>
|
||||
#endif
|
||||
#include "check_integral_constant.hpp"
|
||||
#include "check_type.hpp"
|
||||
|
||||
#define CHECK_FALSE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, false)
|
||||
#define CHECK_TRUE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, true)
|
||||
|
||||
template<class T>
|
||||
using type_t = typename T::type;
|
||||
|
||||
struct has_type {
|
||||
using type = char;
|
||||
};
|
||||
|
||||
struct no_type { };
|
||||
|
||||
TT_TEST_BEGIN(is_detected_convertible)
|
||||
|
||||
CHECK_FALSE((::tt::is_detected_convertible<long, type_t, int>::value));
|
||||
CHECK_TRUE((::tt::is_detected_convertible<long, type_t, has_type>::value));
|
||||
CHECK_FALSE((::tt::is_detected_convertible<long, type_t, no_type>::value));
|
||||
#ifndef BOOST_NO_CXX14_VARIABLE_TEMPLATES
|
||||
CHECK_FALSE((::tt::is_detected_convertible_v<long, type_t, int>));
|
||||
CHECK_TRUE((::tt::is_detected_convertible_v<long, type_t, has_type>));
|
||||
CHECK_FALSE((::tt::is_detected_convertible_v<long, type_t, no_type>));
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2017-2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||
#ifdef TEST_STD
|
||||
#include <type_traits>
|
||||
#else
|
||||
#include <boost/type_traits/is_detected_exact.hpp>
|
||||
#endif
|
||||
#include "check_integral_constant.hpp"
|
||||
#include "check_type.hpp"
|
||||
|
||||
#define CHECK_FALSE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, false)
|
||||
#define CHECK_TRUE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, true)
|
||||
|
||||
template<class T>
|
||||
using type_t = typename T::type;
|
||||
|
||||
struct has_type {
|
||||
using type = char;
|
||||
};
|
||||
|
||||
struct no_type { };
|
||||
|
||||
TT_TEST_BEGIN(is_detected_exact)
|
||||
|
||||
CHECK_FALSE((::tt::is_detected_exact<char, type_t, int>::value));
|
||||
CHECK_TRUE((::tt::is_detected_exact<char, type_t, has_type>::value));
|
||||
CHECK_FALSE((::tt::is_detected_exact<char, type_t, no_type>::value));
|
||||
#ifndef BOOST_NO_CXX14_VARIABLE_TEMPLATES
|
||||
CHECK_FALSE((::tt::is_detected_exact_v<char, type_t, int>));
|
||||
CHECK_TRUE((::tt::is_detected_exact_v<char, type_t, has_type>));
|
||||
CHECK_FALSE((::tt::is_detected_exact_v<char, type_t, no_type>));
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright 2017-2018 Glen Joseph Fernandes
|
||||
<glenjofe -at- gmail.com>
|
||||
|
||||
Distributed under the Boost Software License,
|
||||
Version 1.0. (See accompanying file LICENSE_1_0.txt
|
||||
or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
*/
|
||||
#include <boost/config.hpp>
|
||||
#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
|
||||
!defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
|
||||
#ifdef TEST_STD
|
||||
#include <type_traits>
|
||||
#else
|
||||
#include <boost/type_traits/is_detected.hpp>
|
||||
#endif
|
||||
#include "check_integral_constant.hpp"
|
||||
#include "check_type.hpp"
|
||||
|
||||
#define CHECK_FALSE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, false)
|
||||
#define CHECK_TRUE(e) BOOST_CHECK_INTEGRAL_CONSTANT(e, true)
|
||||
|
||||
template<class T>
|
||||
using type_t = typename T::type;
|
||||
|
||||
struct has_type {
|
||||
using type = char;
|
||||
};
|
||||
|
||||
struct no_type { };
|
||||
|
||||
TT_TEST_BEGIN(is_detected)
|
||||
|
||||
CHECK_FALSE((::tt::is_detected<type_t, int>::value));
|
||||
CHECK_TRUE((::tt::is_detected<type_t, has_type>::value));
|
||||
CHECK_FALSE((::tt::is_detected<type_t, no_type>::value));
|
||||
#ifndef BOOST_NO_CXX14_VARIABLE_TEMPLATES
|
||||
CHECK_FALSE((::tt::is_detected_v<type_t, int>));
|
||||
CHECK_TRUE((::tt::is_detected_v<type_t, has_type>));
|
||||
CHECK_FALSE((::tt::is_detected_v<type_t, no_type>));
|
||||
#endif
|
||||
|
||||
TT_TEST_END
|
||||
#else
|
||||
int main()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
Reference in new issue
Block a user