diff --git a/CMakeLists.txt b/CMakeLists.txt index d21a29a1..f7282a3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ target_include_directories( "$" ) -target_compile_features(fplus INTERFACE cxx_std_14) +target_compile_features(fplus INTERFACE cxx_std_17) find_package(Threads REQUIRED) target_link_libraries(fplus INTERFACE Threads::Threads) diff --git a/include/fplus/function_traits.hpp b/include/fplus/function_traits.hpp index 9598f748..9c0bac76 100644 --- a/include/fplus/function_traits.hpp +++ b/include/fplus/function_traits.hpp @@ -100,7 +100,6 @@ namespace utils { R (C::*)(A...)>::type>::type type; }; } - template struct function_traits { /** @@ -441,7 +440,7 @@ namespace internal { }; template - struct has_function_traits : std::true_type { + struct has_function_traits : std::true_type { }; template diff --git a/include/fplus/variant.hpp b/include/fplus/variant.hpp index 732ffa38..6e7f866f 100644 --- a/include/fplus/variant.hpp +++ b/include/fplus/variant.hpp @@ -93,23 +93,21 @@ namespace internal { typedef std::shared_ptr type; }; - // http://stackoverflow.com/a/27588263/1866775 - - template - struct get_index; - - template - struct get_index : std::integral_constant { + template + struct contains { + /// True if T is in Ts... + constexpr static bool value = (std::is_same_v || ...); }; - template - struct get_index : std::integral_constant::value> { - }; - - template - struct get_index { - // condition is always false, but should be dependant of T - static_assert(sizeof(T) == 0, "element not found"); + template + struct get_index { + /// Index of type T in List. + static_assert(contains::value, "element is not in list"); + constexpr static auto value = []() { + return ([]() {std::size_t i = 0; + (... && (!std::is_same_v && ++i)); + return i; }()); + }(); }; template diff --git a/include_all_in_one/include/fplus/fplus.hpp b/include_all_in_one/include/fplus/fplus.hpp index 80894cdd..bf290851 100644 --- a/include_all_in_one/include/fplus/fplus.hpp +++ b/include_all_in_one/include/fplus/fplus.hpp @@ -344,22 +344,6 @@ namespace utils { : public function_traits { }; - namespace xx_impl { - template - struct memfn_type { - typedef typename std::conditional< - std::is_const::value, - typename std::conditional< - std::is_volatile::value, - R (C::*)(A...) const volatile, - R (C::*)(A...) const>::type, - typename std::conditional< - std::is_volatile::value, - R (C::*)(A...) volatile, - R (C::*)(A...)>::type>::type type; - }; - } - template struct function_traits { /** @@ -404,6 +388,22 @@ namespace utils { }; }; + namespace xx_impl { + template + struct memfn_type { + typedef typename std::conditional< + std::is_const::value, + typename std::conditional< + std::is_volatile::value, + R (C::*)(A...) const volatile, + R (C::*)(A...) const>::type, + typename std::conditional< + std::is_volatile::value, + R (C::*)(A...) volatile, + R (C::*)(A...)>::type>::type type; + }; + } + #if __cplusplus > 201510L template @@ -700,7 +700,7 @@ namespace internal { }; template - struct has_function_traits : std::true_type { + struct has_function_traits : std::true_type { }; template @@ -3295,7 +3295,7 @@ namespace internal { std::size_t pos_; }; -#if defined(_MSC_VER) && _MSC_VER >= 1900 +#if defined(_MSC_VER) && _MSC_VER >= 1900 && _MSC_VER < 1915 template struct std::_Is_checked_helper> : public true_type { // mark array_back_insert_iterator as checked @@ -14329,23 +14329,21 @@ namespace internal { typedef std::shared_ptr type; }; - // http://stackoverflow.com/a/27588263/1866775 - - template - struct get_index; - - template - struct get_index : std::integral_constant { - }; - - template - struct get_index : std::integral_constant::value> { + template + struct contains { + /// True if T is in Ts... + constexpr static bool value = (std::is_same_v || ...); }; - template - struct get_index { - // condition is always false, but should be dependant of T - static_assert(sizeof(T) == 0, "element not found"); + template + struct get_index { + /// Index of type T in List. + static_assert(contains::value, "element is not in list"); + constexpr static auto value = []() { + return ([]() {std::size_t i = 0; + (... && (!std::is_same_v && ++i)); + return i; }()); + }(); }; template diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 0a10914a..025344cf 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -15,9 +15,7 @@ include(../cmake/warnings.cmake) find_package(doctest 2.4.11 CONFIG REQUIRED) # for doctest_discover_tests include(doctest) - enable_testing() - set( tests show_versions @@ -75,6 +73,6 @@ foreach (name IN LISTS tests) FunctionalPlus::fplus doctest::doctest ) - target_compile_features("${name}" PRIVATE cxx_std_14) + target_compile_features("${name}" PRIVATE cxx_std_17) doctest_discover_tests("${name}") endforeach ()