From aa50c6b65ad077e8c0027c5627dc312525a5defc Mon Sep 17 00:00:00 2001 From: Jeremy Nimmer Date: Wed, 28 Nov 2018 19:31:49 -0500 Subject: [PATCH] Fix duplicate definition of stx::in_place and related In some cases, optional.hpp and variant.hpp still could not be included in the same translation unit: (1) If the user included variant.hpp first and optional.hpp second and if was available, we'd see duplicate inplace_t and inplace. (2) If the user included optional.hpp first and variant.hpp second and if was available, we'd see duplicate inplace_t and inplace. (3) If the user included optional.hpp first and variant.hpp second and if was not available, we'd see duplicate in_place_type_t, in_place_type, in_place_index_t, and in_place_index. This improves on 6da04dc9898a2bc1724575b339d983b053d20d4f. --- include/stx/optional.hpp | 24 ++++++------------------ include/stx/variant.hpp | 2 +- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/include/stx/optional.hpp b/include/stx/optional.hpp index 3f8c556..132e33a 100644 --- a/include/stx/optional.hpp +++ b/include/stx/optional.hpp @@ -37,8 +37,11 @@ using std::nullopt_t; using std::nullopt; using std::make_optional; +# ifndef STX_HAVE_IN_PLACE_T using std::in_place_t; using std::in_place; +# define STX_HAVE_IN_PLACE_T 1 +# endif // STX_HAVE_IN_PLACE_T } # define STX_HAVE_STD_OPTIONAL 1 # elif __has_include() @@ -49,8 +52,11 @@ using std::experimental::nullopt_t; using std::experimental::nullopt; using std::experimental::make_optional; +# ifndef STX_HAVE_IN_PLACE_T using std::experimental::in_place_t; using std::experimental::in_place; +# define STX_HAVE_IN_PLACE_T 1 +# endif // STX_HAVE_IN_PLACE_T } # define STX_HAVE_STD_OPTIONAL 1 # endif // __hasinclude(optional) @@ -299,24 +305,6 @@ struct in_place_t { constexpr in_place_t in_place{}; -template struct in_place_type_t { - explicit in_place_type_t() = default; -}; - - -template struct in_place_index_t { - explicit in_place_index_t() = default; -}; - - -#if __cpp_variable_templates >= 201304 -template -constexpr in_place_type_t in_place_type{}; -template -constexpr in_place_index_t in_place_index{}; -#endif // __cpp_variable_templates - - #define STX_HAVE_IN_PLACE_T #endif // STX_HAVE_IN_PLACE_T diff --git a/include/stx/variant.hpp b/include/stx/variant.hpp index dbf79e6..4d6d41c 100644 --- a/include/stx/variant.hpp +++ b/include/stx/variant.hpp @@ -57,7 +57,7 @@ # ifndef STX_HAVE_IN_PLACE_T using std::in_place_t; using std::in_place; -# define STX_IN_PLACE_T 1 +# define STX_HAVE_IN_PLACE_T 1 # endif using std::in_place_type_t; using std::in_place_type;