From b9d0bf8822b13e3bdd3a3b91d92df1b538fab25f Mon Sep 17 00:00:00 2001 From: Vinnie Falco Date: Mon, 3 Mar 2014 13:37:07 -0800 Subject: [PATCH] Consolidate C++14 compatibility into new headers --- Builds/VisualStudio2013/beast.vcxproj | 9 +- Builds/VisualStudio2013/beast.vcxproj.filters | 30 ++-- .../container/detail/aged_ordered_container.h | 7 +- .../detail/aged_unordered_container.h | 6 +- .../impl/aged_associative_container.cpp | 1 - beast/{equal.h => cxx14/algorithm.h} | 10 +- beast/cxx14/config.h | 44 ++++++ beast/{equal_to.h => cxx14/functional.h} | 20 +-- beast/cxx14/memory.h | 41 +++++ beast/cxx14/type_traits.h | 147 ++++++++++++++++++ beast/insight/impl/Groups.cpp | 2 +- beast/is_constructible.h | 76 --------- beast/make_unique.h | 99 ------------ 13 files changed, 277 insertions(+), 215 deletions(-) rename beast/{equal.h => cxx14/algorithm.h} (95%) create mode 100644 beast/cxx14/config.h rename beast/{equal_to.h => cxx14/functional.h} (85%) create mode 100644 beast/cxx14/memory.h create mode 100644 beast/cxx14/type_traits.h delete mode 100644 beast/is_constructible.h delete mode 100644 beast/make_unique.h diff --git a/Builds/VisualStudio2013/beast.vcxproj b/Builds/VisualStudio2013/beast.vcxproj index 2d2943b2b..899aecb55 100644 --- a/Builds/VisualStudio2013/beast.vcxproj +++ b/Builds/VisualStudio2013/beast.vcxproj @@ -138,9 +138,12 @@ + + + + + - - @@ -168,8 +171,6 @@ - - diff --git a/Builds/VisualStudio2013/beast.vcxproj.filters b/Builds/VisualStudio2013/beast.vcxproj.filters index bb202a9de..568e628c0 100644 --- a/Builds/VisualStudio2013/beast.vcxproj.filters +++ b/Builds/VisualStudio2013/beast.vcxproj.filters @@ -306,6 +306,9 @@ {8832eb52-53f9-4850-8dc9-1d579a386a0e} + + {5745a887-7df8-4059-87ea-e0c7eea77a9b} + @@ -1212,9 +1215,6 @@ beast\asio - - beast - beast\insight @@ -1269,12 +1269,6 @@ beast\chrono - - beast - - - beast - beast\type_traits @@ -1320,15 +1314,27 @@ beast\container\detail - - beast - beast\container beast\container + + beast\cxx14 + + + beast\cxx14 + + + beast\cxx14 + + + beast\cxx14 + + + beast\cxx14 + diff --git a/beast/container/detail/aged_ordered_container.h b/beast/container/detail/aged_ordered_container.h index 7c933d60d..dd151b317 100644 --- a/beast/container/detail/aged_ordered_container.h +++ b/beast/container/detail/aged_ordered_container.h @@ -23,12 +23,12 @@ #include "aged_container_iterator.h" #include "aged_associative_container.h" +#include "../../cxx14/algorithm.h" +#include "../../cxx14/type_traits.h" + #include "../aged_container.h" #include "../../chrono/abstract_clock.h" -#include "../../equal.h" -#include "../../equal_to.h" -#include "../../is_constructible.h" #include "../../utility/empty_base_optimization.h" #include @@ -38,7 +38,6 @@ #include #include #include -#include #include namespace beast { diff --git a/beast/container/detail/aged_unordered_container.h b/beast/container/detail/aged_unordered_container.h index 23af08bba..2eac2783a 100644 --- a/beast/container/detail/aged_unordered_container.h +++ b/beast/container/detail/aged_unordered_container.h @@ -26,19 +26,17 @@ #include "../aged_container.h" #include "../../chrono/abstract_clock.h" -#include "../../equal.h" -#include "../../equal_to.h" -#include "../../is_constructible.h" #include "../../utility/empty_base_optimization.h" #include #include +#include "../../cxx14/algorithm.h" +#include "../../cxx14/type_traits.h" #include #include #include #include -#include #include /* diff --git a/beast/container/impl/aged_associative_container.cpp b/beast/container/impl/aged_associative_container.cpp index bb2cd715f..c1671ba7f 100644 --- a/beast/container/impl/aged_associative_container.cpp +++ b/beast/container/impl/aged_associative_container.cpp @@ -19,7 +19,6 @@ #include "../../../modules/beast_core/beast_core.h" // for UnitTest #include "../../chrono/manual_clock.h" -#include "../../equal.h" #include "../aged_set.h" #include "../aged_map.h" #include "../aged_multiset.h" diff --git a/beast/equal.h b/beast/cxx14/algorithm.h similarity index 95% rename from beast/equal.h rename to beast/cxx14/algorithm.h index e8593382c..c72a631bc 100644 --- a/beast/equal.h +++ b/beast/cxx14/algorithm.h @@ -17,13 +17,13 @@ */ //============================================================================== -#ifndef BEAST_EQUAL_H_INCLUDED -#define BEAST_EQUAL_H_INCLUDED +#ifndef BEAST_CXX14_ALGORITHM_H_INCLUDED +#define BEAST_CXX14_ALGORITHM_H_INCLUDED -#include "equal_to.h" +#include "config.h" +#include "functional.h" -#include -#include +#include namespace std { diff --git a/beast/cxx14/config.h b/beast/cxx14/config.h new file mode 100644 index 000000000..841e9052c --- /dev/null +++ b/beast/cxx14/config.h @@ -0,0 +1,44 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_CXX14_CONFIG_H_INCLUDED +#define BEAST_CXX14_CONFIG_H_INCLUDED + +// Sets C++14 compatibility configuration macros based on build environment + +// Disables beast c++14 compatibility additions when set to 1 +// +#ifndef BEAST_NO_CXX14_COMPATIBILITY +# ifdef _MSC_VER +# define BEAST_NO_CXX14_COMPATIBILITY 1 +# else +# define BEAST_NO_CXX14_COMPATIBILITY 0 +# endif +#endif + +// Disables beast's make_unique +#ifndef BEAST_NO_CXX14_MAKE_UNIQUE +# ifdef _MSC_VER +# define BEAST_NO_CXX14_MAKE_UNIQUE 1 +# else +# define BEAST_NO_CXX14_MAKE_UNIQUE 0 +# endif +#endif + +#endif diff --git a/beast/equal_to.h b/beast/cxx14/functional.h similarity index 85% rename from beast/equal_to.h rename to beast/cxx14/functional.h index 8e66f9b2b..35946b881 100644 --- a/beast/equal_to.h +++ b/beast/cxx14/functional.h @@ -17,19 +17,21 @@ */ //============================================================================== -#ifndef BEAST_EQUAL_TO_H_INCLUDED -#define BEAST_EQUAL_TO_H_INCLUDED +#ifndef BEAST_CXX14_FUNCTIONAL_H_INCLUDED +#define BEAST_CXX14_FUNCTIONAL_H_INCLUDED + +#include "config.h" #include #include +#include + +#if ! BEAST_NO_CXX14_COMPATIBILITY namespace std { -#ifndef _MSC_VER - -/** C++14 implementation of std::equal_to specialization. - This supports heterogeneous comparisons. -*/ +// C++14 implementation of std::equal_to specialization. +// This supports heterogeneous comparisons. template <> struct equal_to { @@ -44,8 +46,8 @@ struct equal_to } }; -#endif - } #endif + +#endif diff --git a/beast/cxx14/memory.h b/beast/cxx14/memory.h new file mode 100644 index 000000000..6c92471cc --- /dev/null +++ b/beast/cxx14/memory.h @@ -0,0 +1,41 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_CXX14_MEMORY_H_INCLUDED +#define BEAST_CXX14_MEMORY_H_INCLUDED + +#include "config.h" + +#include + +namespace std { + +#if ! BEAST_NO_CXX14_MAKE_UNIQUE + +template +std::unique_ptr make_unique (Args&&... args) +{ + return std::unique_ptr (new T (std::forward (args)...)); +} + +#endif + +} + +#endif diff --git a/beast/cxx14/type_traits.h b/beast/cxx14/type_traits.h new file mode 100644 index 000000000..cc86df938 --- /dev/null +++ b/beast/cxx14/type_traits.h @@ -0,0 +1,147 @@ +//------------------------------------------------------------------------------ +/* + This file is part of Beast: https://github.com/vinniefalco/Beast + Copyright 2013, Vinnie Falco + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_CXX14_TYPE_TRAITS_H_INCLUDED +#define BEAST_CXX14_TYPE_TRAITS_H_INCLUDED + +#include "config.h" + +#include +#include +#include + +namespace std { + +// Ideas from Howard Hinnant +// +// Specializations of is_constructible for pair and tuple which +// work around an apparent defect in the standard that causes well +// formed expressions involving pairs or tuples of non default-constructible +// types to generate compile errors. +// +template +struct is_constructible > + : integral_constant ::value && + is_default_constructible ::value> +{ +}; + +namespace detail { + +template +struct compile_time_all; + +template <> +struct compile_time_all <> +{ + static const bool value = true; +}; + +template +struct compile_time_all +{ + static const bool value = + Arg0 && compile_time_all ::value; +}; + +} + +template +struct is_constructible > + : integral_constant ::value...>::value> +{ +}; + +//------------------------------------------------------------------------------ + +#if ! BEAST_NO_CXX14_COMPATIBILITY + +// From http://llvm.org/svn/llvm-project/libcxx/trunk/include/type_traits + +// const-volatile modifications: +template +using remove_const_t = typename remove_const::type; // C++14 +template +using remove_volatile_t = typename remove_volatile::type; // C++14 +template +using remove_cv_t = typename remove_cv::type; // C++14 +template +using add_const_t = typename add_const::type; // C++14 +template +using add_volatile_t = typename add_volatile::type; // C++14 +template +using add_cv_t = typename add_cv::type; // C++14 + +// reference modifications: +template +using remove_reference_t = typename remove_reference::type; // C++14 +template +using add_lvalue_reference_t = typename add_lvalue_reference::type; // C++14 +template +using add_rvalue_reference_t = typename add_rvalue_reference::type; // C++14 + +// sign modifications: +template +using make_signed_t = typename make_signed::type; // C++14 +template +using make_unsigned_t = typename make_unsigned::type; // C++14 + +// array modifications: +template +using remove_extent_t = typename remove_extent::type; // C++14 +template +using remove_all_extents_t = typename remove_all_extents::type; // C++14 + +// pointer modifications: +template +using remove_pointer_t = typename remove_pointer::type; // C++14 +template +using add_pointer_t = typename add_pointer::type; // C++14 + +// other transformations: + +#if 0 +// This is not easy to implement in C++11 +template ::value> +using aligned_storage_t = typename aligned_storage::type; // C++14 +template +using aligned_union_t = typename aligned_union::type; // C++14 +#endif + +template +using decay_t = typename decay::type; // C++14 +template +using enable_if_t = typename enable_if::type; // C++14 +template +using conditional_t = typename conditional::type; // C++14 +template +using common_type_t = typename common_type::type; // C++14 +template +using underlying_type_t = typename underlying_type::type; // C++14 +template +using result_of_t = typename result_of::type; // C++14 + +#endif + +} + +#endif diff --git a/beast/insight/impl/Groups.cpp b/beast/insight/impl/Groups.cpp index 0ce674e0d..f336c56ae 100644 --- a/beast/insight/impl/Groups.cpp +++ b/beast/insight/impl/Groups.cpp @@ -19,7 +19,7 @@ #include -#include "../../make_unique.h" +#include "../../cxx14/memory.h" namespace beast { namespace insight { diff --git a/beast/is_constructible.h b/beast/is_constructible.h deleted file mode 100644 index de8fd6870..000000000 --- a/beast/is_constructible.h +++ /dev/null @@ -1,76 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Howard Hinnant , - Vinnie Falco - - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_IS_CONSTRUCTIBLE_H_INCLUDED -#define BEAST_IS_CONSTRUCTIBLE_H_INCLUDED - -#include -#include -#include - -namespace std { - -// Ideas from Howard Hinnant -// -// Specializations of is_constructible for pair and tuple which -// work around an apparent defect in the standard that causes well -// formed expressions involving pairs or tuples of non default-constructible -// types to generate compile errors. -// -template -struct is_constructible > - : integral_constant ::value && - is_default_constructible ::value> -{ -}; - -namespace detail { - -template -struct compile_time_all; - -template <> -struct compile_time_all <> -{ - static const bool value = true; -}; - -template -struct compile_time_all -{ - static const bool value = - Arg0 && compile_time_all ::value; -}; - -} - -template -struct is_constructible > - : integral_constant ::value...>::value> -{ -}; - -} - -#endif diff --git a/beast/make_unique.h b/beast/make_unique.h deleted file mode 100644 index e26402ae2..000000000 --- a/beast/make_unique.h +++ /dev/null @@ -1,99 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2013, Vinnie Falco - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_MAKE_UNIQUE_H_INCLUDED -#define BEAST_MAKE_UNIQUE_H_INCLUDED - -#include - -namespace std { - -#ifndef BOOST_NO_CXX11_VARIADIC_TEMPLATES -# ifdef _MSC_VER -# define BOOST_NO_CXX11_VARIADIC_TEMPLATES -# endif -#endif - -#ifdef BOOST_NO_CXX11_VARIADIC_TEMPLATES - -template -std::unique_ptr make_unique () -{ - return std::unique_ptr (new T); -} - -template -std::unique_ptr make_unique (P1&& p1) -{ - return std::unique_ptr (new T (std::forward (p1))); -} - -template -std::unique_ptr make_unique (P1&& p1, P2&& p2) -{ - return std::unique_ptr (new T ( - std::forward (p1), std::forward (p2))); -} - -template -std::unique_ptr make_unique (P1&& p1, P2&& p2, P3&& p3) -{ - return std::unique_ptr (new T ( - std::forward (p1), std::forward (p2), std::forward (p3))); -} - -template -std::unique_ptr make_unique (P1&& p1, P2&& p2, P3&& p3, P4&& p4) -{ - return std::unique_ptr (new T ( - std::forward (p1), std::forward (p2), std::forward (p3), - std::forward (p4))); -} - -template -std::unique_ptr make_unique (P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5) -{ - return std::unique_ptr (new T ( - std::forward (p1), std::forward (p2), std::forward (p3), - std::forward (p4), std::forward (p5))); -} - -template -std::unique_ptr make_unique (P1&& p1, P2&& p2, P3&& p3, P4&& p4, P5&& p5, P6&& p6) -{ - return std::unique_ptr (new T ( - std::forward (p1), std::forward (p2), std::forward (p3), - std::forward (p4), std::forward (p5), std::forward (p6))); -} - -//------------------------------------------------------------------------------ - -#else - -template -std::unique_ptr make_unique (Args&&... args) -{ - return std::unique_ptr (new T (std::forward (args)...)); -} - -#endif - -} - -#endif