From d24f722c5aa2d4a48f9edb6800d4e29add735b47 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Mon, 30 Jan 2017 08:47:47 -0500 Subject: [PATCH] Add make_void and void_t traits --- doc/make_void.qbk | 47 +++++++++++++++++++++++++ doc/type_traits.qbk | 2 ++ include/boost/type_traits.hpp | 1 + include/boost/type_traits/make_void.hpp | 41 +++++++++++++++++++++ test/make_void_test.cpp | 34 ++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 doc/make_void.qbk create mode 100644 include/boost/type_traits/make_void.hpp create mode 100644 test/make_void_test.cpp diff --git a/doc/make_void.qbk b/doc/make_void.qbk new file mode 100644 index 0000000..eb103fb --- /dev/null +++ b/doc/make_void.qbk @@ -0,0 +1,47 @@ +[/ +Copyright 2017 Glen Joseph Fernandes + + +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). +] + +[section:make_void make_void] + + template + struct make_void + { + typedef void type; + }; + + template + using void_t = typename make_void::type; + +__type The type `void` for all `T`. + +__header ` #include ` or ` #include ` + +[table Examples + +[[Expression] [Result Type]] + +[[`make_void::type`][`void`]] + +[[`make_void::type`] [`void`]] + +[[`make_void::type`] [`void`]] + +[[`make_void::type`] [`void`]] + +[[`make_void::type`] [`void`]] + +[[`make_void<>::type`] [`void`]] + +[[`make_void::type`] [`void`]] + +] + +[all_compilers] + +[endsect] diff --git a/doc/type_traits.qbk b/doc/type_traits.qbk index 8a914a4..dd9bfc6 100644 --- a/doc/type_traits.qbk +++ b/doc/type_traits.qbk @@ -134,6 +134,7 @@ [def __make_signed [link boost_typetraits.reference.make_signed make_signed]] [def __make_unsigned [link boost_typetraits.reference.make_unsigned make_unsigned]] +[def __make_void [link boost_typetraits.reference.make_void make_void]] [def __decay [link boost_typetraits.reference.decay decay]] [def __is_complex [link boost_typetraits.reference.is_complex is_complex]] @@ -316,6 +317,7 @@ See __has_trivial_constructor. [include make_signed.qbk] [include make_unsigned.qbk] +[include make_void.qbk] [include promote.qbk] [include rank.qbk] diff --git a/include/boost/type_traits.hpp b/include/boost/type_traits.hpp index 7d651ce..93a992d 100644 --- a/include/boost/type_traits.hpp +++ b/include/boost/type_traits.hpp @@ -130,6 +130,7 @@ #include #include #include +#include #include #include #include diff --git a/include/boost/type_traits/make_void.hpp b/include/boost/type_traits/make_void.hpp new file mode 100644 index 0000000..6ee34dd --- /dev/null +++ b/include/boost/type_traits/make_void.hpp @@ -0,0 +1,41 @@ +/* +Copyright 2017 Glen Joseph Fernandes + + +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_MAKE_VOID_HPP_INCLUDED +#define BOOST_TT_MAKE_VOID_HPP_INCLUDED + +#include + +namespace boost { + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +template +struct make_void { + typedef void type; +}; + +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +template +using void_t = typename make_void::type; +#endif +#else +template +struct make_void { + typedef void type; +}; + +#if !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) +template +using void_t = typename make_void::type; +#endif +#endif + +} /* boost */ + +#endif diff --git a/test/make_void_test.cpp b/test/make_void_test.cpp new file mode 100644 index 0000000..028b132 --- /dev/null +++ b/test/make_void_test.cpp @@ -0,0 +1,34 @@ +/* +Copyright 2017 Glen Joseph Fernandes + + +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 "test.hpp" +#include "check_type.hpp" + +#ifdef TEST_STD +#include +#else +#include +#endif + +TT_TEST_BEGIN(make_void) + +BOOST_CHECK_TYPE(::tt::make_void::type, void); +BOOST_CHECK_TYPE(::tt::make_void::type, void); +BOOST_CHECK_TYPE(::tt::make_void::type, void); +BOOST_CHECK_TYPE(::tt::make_void::type, void); +BOOST_CHECK_TYPE(::tt::make_void::type, void); +BOOST_CHECK_TYPE(::tt::make_void::type, void); +BOOST_CHECK_TYPE(::tt::make_void::type, void); + +#if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) +BOOST_CHECK_TYPE(::tt::make_void<>::type, void); +BOOST_CHECK_TYPE3(::tt::make_void::type, void); +#endif + +TT_TEST_END