Implement detection idiom toolkit

This commit is contained in:
Glen Fernandes committed 2018-01-28 09:40:24 -05:00
1 parent 5d5c651ea6
commit 35c105501b
21 files changed
+662 -2

No files matched your search

@@ -0,0 +1,35 @@
/*
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)
*/
#ifndef BOOST_TT_DETAIL_DETECTOR_HPP_INCLUDED
#define BOOST_TT_DETAIL_DETECTOR_HPP_INCLUDED
#include <boost/type_traits/integral_constant.hpp>
#include <boost/type_traits/make_void.hpp>
namespace boost {
namespace detail {
template<class Default, class, template<class...> class, class...>
struct detector {
using value_t = boost::false_type;
using type = Default;
};
template<class Default, template<class...> class Op, class... Args>
struct detector<Default, typename boost::make_void<Op<Args...> >::type, Op,
Args...> {
using value_t = boost::true_type;
using type = Op<Args...>;
};
} /* detail */
} /* boost */
#endif
+24
View File
@@ -0,0 +1,24 @@
/*
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)
*/
#ifndef BOOST_TT_DETECTED_HPP_INCLUDED
#define BOOST_TT_DETECTED_HPP_INCLUDED
#include <boost/type_traits/detail/detector.hpp>
#include <boost/type_traits/nonesuch.hpp>
namespace boost {
template<template<class...> class Op, class... Args>
using detected_t = typename
detail::detector<nonesuch, void, Op, Args...>::type;
} /* boost */
#endif
+25
View File
@@ -0,0 +1,25 @@
/*
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)
*/
#ifndef BOOST_TT_DETECTED_OR_HPP_INCLUDED
#define BOOST_TT_DETECTED_OR_HPP_INCLUDED
#include <boost/type_traits/detail/detector.hpp>
namespace boost {
template<class Default, template<class...> class Op, class... Args>
using detected_or = detail::detector<Default, void, Op, Args...>;
template<class Default, template<class...> class Op, class... Args>
using detected_or_t = typename detected_or<Default, Op, Args...>::type;
} /* boost */
#endif
+29
View File
@@ -0,0 +1,29 @@
/*
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)
*/
#ifndef BOOST_TT_IS_DETECTED_HPP_INCLUDED
#define BOOST_TT_IS_DETECTED_HPP_INCLUDED
#include <boost/type_traits/detail/detector.hpp>
#include <boost/type_traits/nonesuch.hpp>
namespace boost {
template<template<class...> class Op, class... Args>
using is_detected = typename
detail::detector<nonesuch, void, Op, Args...>::value_t;
#if !defined(BOOST_NO_CXX14_VARIABLE_TEMPLATES)
template<template<class...> class Op, class... Args>
constexpr bool is_detected_v = is_detected<Op, Args...>::value;
#endif
} /* boost */
#endif
@@ -0,0 +1,29 @@
/*
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)
*/
#ifndef BOOST_TT_IS_DETECTED_CONVERTIBLE_HPP_INCLUDED
#define BOOST_TT_IS_DETECTED_CONVERTIBLE_HPP_INCLUDED
#include <boost/type_traits/detected.hpp>
#include <boost/type_traits/is_convertible.hpp>
namespace boost {
template<class To, template<class...> class Op, class... Args>
using is_detected_convertible = is_convertible<detected_t<Op, Args...>, To>;
#if !defined(BOOST_NO_CXX14_VARIABLE_TEMPLATES)
template<class To, template<class...> class Op, class... Args>
constexpr bool is_detected_convertible_v = is_detected_convertible<To, Op,
Args...>::value;
#endif
} /* boost */
#endif
@@ -0,0 +1,29 @@
/*
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)
*/
#ifndef BOOST_TT_IS_DETECTED_EXACT_HPP_INCLUDED
#define BOOST_TT_IS_DETECTED_EXACT_HPP_INCLUDED
#include <boost/type_traits/detected.hpp>
#include <boost/type_traits/is_same.hpp>
namespace boost {
template<class Expected, template<class...> class Op, class... Args>
using is_detected_exact = is_same<Expected, detected_t<Op, Args...> >;
#if !defined(BOOST_NO_CXX14_VARIABLE_TEMPLATES)
template<class Expected, template<class...> class Op, class... Args>
constexpr bool is_detected_exact_v = is_detected_exact<Expected, Op,
Args...>::value;
#endif
} /* boost */
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
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)
*/
#ifndef BOOST_TT_NONESUCH_HPP_INCLUDED
#define BOOST_TT_NONESUCH_HPP_INCLUDED
#include <boost/config.hpp>
namespace boost {
#if !defined(BOOST_NO_CXX11_DELETED_FUNCTIONS)
struct nonesuch {
nonesuch() = delete;
~nonesuch() = delete;
nonesuch(const nonesuch&) = delete;
void operator=(const nonesuch&) = delete;
};
#else
class nonesuch {
nonesuch();
~nonesuch();
nonesuch(const nonesuch&);
void operator=(const nonesuch&);
};
#endif
} /* boost */
#endif