diff --git a/cmake/ProjectGlobalMacros.cmake b/cmake/ProjectGlobalMacros.cmake index 315d51d..3cbce7d 100644 --- a/cmake/ProjectGlobalMacros.cmake +++ b/cmake/ProjectGlobalMacros.cmake @@ -131,7 +131,7 @@ macro(project_enable_clang_format) if (NOT ${CLANG_FORMAT_EXE} STREQUAL "CLANG_FORMAT_EXE-NOTFOUND") message("-- clang-format found, whole source formatting enabled through 'format' target.") add_custom_target(format - COMMAND find ./src -type f -regex .*\\.h\\\|.*\\.hpp\\\|.*\\.hxx\\\|.*\\.c\\\|.*\\.cpp\\\|.*\\.cxx\\\|.*\\.cc -exec clang-format -i {} \; + COMMAND find ./includes -type f -regex .*\\.h\\\|.*\\.hpp\\\|.*\\.hxx\\\|.*\\.c\\\|.*\\.cpp\\\|.*\\.cxx\\\|.*\\.cc -exec clang-format -i {} \; WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} VERBATIM ) diff --git a/cmake/ProjectTestFunctions.cmake b/cmake/ProjectTestFunctions.cmake index 68a735b..8f22865 100644 --- a/cmake/ProjectTestFunctions.cmake +++ b/cmake/ProjectTestFunctions.cmake @@ -1,4 +1,4 @@ -# This file provides function to add tests tp ctest +# This file prmvides function to add tests tp ctest # with additional tooling ## diff --git a/includes/named_types/extensions/factory.hpp b/includes/named_types/extensions/factory.hpp index ede19f2..b494ca0 100644 --- a/includes/named_types/extensions/factory.hpp +++ b/includes/named_types/extensions/factory.hpp @@ -8,8 +8,8 @@ namespace extensions { namespace __factory_impl { template std::function make_builder() { - return ([](Args... args) -> Base * - { return new T(std::forward(args)...); }); + return ( + [](Args... args) -> Base* { return new T(std::forward(args)...); }); } } // namespace __factory_impl @@ -25,8 +25,7 @@ template class factory { named_tuple( __ntuple_tag_spec_t)>::type...>; static builder_tuple_type const builders_{ - __factory_impl::make_builder<__ntuple_tag_elem_t, - BaseClass, + __factory_impl::make_builder<__ntuple_tag_elem_t, BaseClass, BuildArgs...>()...}; static const_rt_view const rt_view_(builders_); auto builder = diff --git a/includes/named_types/extensions/generation_tools.hpp b/includes/named_types/extensions/generation_tools.hpp index 2624b60..5ea9044 100644 --- a/includes/named_types/extensions/generation_tools.hpp +++ b/includes/named_types/extensions/generation_tools.hpp @@ -1,9 +1,9 @@ #pragma once -#include -#include +#include "named_types/extensions/type_traits.hpp" #include "named_types/named_tuple.hpp" #include "named_types/rt_named_tuple.hpp" -#include "named_types/extensions/type_traits.hpp" +#include +#include namespace named_types { namespace extensions { @@ -11,7 +11,7 @@ namespace generation { template struct printf_sequence { using type = void; - static T evaluate(T value){ return value; }; + static T evaluate(T value) { return value; }; }; template <> struct printf_sequence { @@ -61,7 +61,7 @@ template <> struct printf_sequence { static inline double evaluate(double data) { return data; }; }; -//template forward_as_flattened_tuple( +// template forward_as_flattened_tuple( } // namespace generation } // namespace extensions diff --git a/includes/named_types/extensions/parsing_tools.hpp b/includes/named_types/extensions/parsing_tools.hpp index f41cd56..205ad09 100644 --- a/includes/named_types/extensions/parsing_tools.hpp +++ b/includes/named_types/extensions/parsing_tools.hpp @@ -1,13 +1,13 @@ #pragma once -#include +#include "named_types/extensions/type_traits.hpp" +#include "named_types/named_tuple.hpp" +#include "named_types/rt_named_tuple.hpp" #include -#include #include #include +#include #include -#include "named_types/named_tuple.hpp" -#include "named_types/rt_named_tuple.hpp" -#include "named_types/extensions/type_traits.hpp" +#include namespace named_types { namespace extensions { @@ -20,9 +20,9 @@ inline std::enable_if_t::value && is_std_basic_string::value, To> lexical_cast(From const& value) { - std::basic_ostringstream output; + std::basic_ostringstream + output; output << value; return output.str(); } @@ -49,10 +49,9 @@ lexical_cast(From const& value) { } template -inline std::enable_if_t::value && - std::is_arithmetic::value, - To> -lexical_cast(From const& value) { +inline std:: + enable_if_t::value && std::is_arithmetic::value, To> + lexical_cast(From const& value) { To result{}; std::istringstream(value) >> result; return result; @@ -63,8 +62,9 @@ template inline std::enable_if_t::value, std::function> make_setter() { - return [](Tuple& tuple, Source&& source) - -> void { std::get(tuple) = std::move(source); }; + return [](Tuple& tuple, Source&& source) -> void { + std::get(tuple) = std::move(source); + }; } template @@ -144,11 +144,9 @@ inline std::enable_if_t< std::function< value_setter_interface*(Tuple&)>> make_creator() { - return [](Tuple & tuple) - -> value_setter_interface * { - return new value_setter value_setter_interface* { + return new value_setter>( std::get(tuple)); }; @@ -177,11 +175,9 @@ inline std::enable_if_t< std::function< sequence_pusher_interface*(Tuple&)>> make_sequence_creator() { - return [](Tuple & tuple) - -> sequence_pusher_interface * { - return new sequence_pusher sequence_pusher_interface* { + return new sequence_pusher>( std::get(tuple)); }; @@ -346,12 +342,11 @@ class value_setter> rt_view rt_root_; template bool setFrom(size_t field_index, T&& value) { - static std::array, Tuple::size> setters = + static std::array, Tuple::size> setters = {make_setter< - T, - Tuple, + T, Tuple, Tuple::template tag_index<__ntuple_tag_spec_t>::value>()...}; - std::function setter( + std::function setter( field_index < setters.size() ? setters[field_index] : nullptr); if (setter) { setter(root_, std::move(value)); @@ -409,20 +404,17 @@ class value_setter> virtual value_setter_interface* createChildNode(std::basic_string const& key) override { - static std::array< - std::function< - value_setter_interface*(Tuple&)>, - Tuple::size> creators = { - make_creator< - KeyCharT, - ValueCharT, - SizeType, - Tuple, + static std::array*(Tuple&)>, + Tuple::size> + creators = {make_creator< + KeyCharT, ValueCharT, SizeType, Tuple, Tuple::template tag_index<__ntuple_tag_spec_t>::value>()...}; size_t field_index = rt_root_.index_of(key); if (field_index < creators.size()) { std::function*( - Tuple&)> creator = creators[field_index]; + Tuple&)> + creator = creators[field_index]; if (creator) return creator(root_); } @@ -431,20 +423,17 @@ class value_setter> virtual sequence_pusher_interface* createChildSequence(std::basic_string const& key) override { - static std::array< - std::function< - sequence_pusher_interface*(Tuple&)>, - Tuple::size> creators = { - make_sequence_creator< - KeyCharT, - ValueCharT, - SizeType, - Tuple, + static std::array*(Tuple&)>, + Tuple::size> + creators = {make_sequence_creator< + KeyCharT, ValueCharT, SizeType, Tuple, Tuple::template tag_index<__ntuple_tag_spec_t>::value>()...}; size_t field_index = rt_root_.index_of(key); if (field_index < creators.size()) { std::function*( - Tuple&)> creator = creators[field_index]; + Tuple&)> + creator = creators[field_index]; if (creator) return creator(root_); } diff --git a/includes/named_types/extensions/rapidjson.hpp b/includes/named_types/extensions/rapidjson.hpp index 38c0a7b..ffaba63 100644 --- a/includes/named_types/extensions/rapidjson.hpp +++ b/includes/named_types/extensions/rapidjson.hpp @@ -1,12 +1,12 @@ #pragma once +#include "named_types/extensions/type_traits.hpp" +#include "named_types/named_tuple.hpp" +#include "named_types/rt_named_tuple.hpp" #include -#include #include -#include -#include "named_types/named_tuple.hpp" -#include "named_types/extensions/type_traits.hpp" #include -#include "named_types/rt_named_tuple.hpp" +#include +#include namespace named_types { namespace extensions { @@ -15,9 +15,9 @@ namespace rapidjson { template class reader_handler; template -class reader_handler : public ::rapidjson::BaseReaderHandler< - Encoding, - reader_handler> { +class reader_handler + : public ::rapidjson:: + BaseReaderHandler> { static_assert(is_sub_object::value || is_sequence_container::value, "Root type of a handler must either be a named_tuple, an " diff --git a/includes/named_types/extensions/type_traits.hpp b/includes/named_types/extensions/type_traits.hpp index d3bec4a..55a3e07 100644 --- a/includes/named_types/extensions/type_traits.hpp +++ b/includes/named_types/extensions/type_traits.hpp @@ -1,13 +1,13 @@ #pragma once -#include +#include "named_types/named_tuple.hpp" +#include "named_types/rt_named_tuple.hpp" #include -#include #include #include -#include #include -#include "named_types/named_tuple.hpp" -#include "named_types/rt_named_tuple.hpp" +#include +#include +#include namespace named_types { @@ -114,7 +114,7 @@ struct is_static_cast_assignable !std::is_assignable:: value> //&& !std::is_convertible::value; - {}; +{}; template struct tuple_member_assignable @@ -184,90 +184,111 @@ struct __array_to_tuple_impl> { }; template struct array_to_tuple> { - using l_value_reference_forwarded_type = typename __array_to_tuple_impl>::type; - using const_l_value_reference_forwarded_type = typename __array_to_tuple_impl>::type; - using r_value_reference_forwarded_type = typename __array_to_tuple_impl>::type; + using l_value_reference_forwarded_type = + typename __array_to_tuple_impl>::type; + using const_l_value_reference_forwarded_type = + typename __array_to_tuple_impl>:: + type; + using r_value_reference_forwarded_type = + typename __array_to_tuple_impl>::type; private: - template static l_value_reference_forwarded_type forward_impl(std::array& value, std::index_sequence) { - return l_value_reference_forwarded_type(value[Indexes]... ); - } - template static constexpr const_l_value_reference_forwarded_type forward_impl(std::array const& value, std::index_sequence) { - return const_l_value_reference_forwarded_type(value[Indexes]...); - } - template static constexpr r_value_reference_forwarded_type forward_impl(std::array&& value, std::index_sequence) { - return r_value_reference_forwarded_type(std::move(value[Indexes])... ); - } + template + static l_value_reference_forwarded_type + forward_impl(std::array& value, std::index_sequence) { + return l_value_reference_forwarded_type(value[Indexes]...); + } + template + static constexpr const_l_value_reference_forwarded_type + forward_impl(std::array const& value, std::index_sequence) { + return const_l_value_reference_forwarded_type(value[Indexes]...); + } + template + static constexpr r_value_reference_forwarded_type + forward_impl(std::array&& value, std::index_sequence) { + return r_value_reference_forwarded_type(std::move(value[Indexes])...); + } + public: - using type = + using type = typename __array_to_tuple_impl>::type; - static constexpr l_value_reference_forwarded_type forward(std::array& value) { + static constexpr l_value_reference_forwarded_type + forward(std::array& value) { return forward_impl(value, std::make_index_sequence()); } - static constexpr const_l_value_reference_forwarded_type forward(std::array const& value) { + static constexpr const_l_value_reference_forwarded_type + forward(std::array const& value) { return forward_impl(value, std::make_index_sequence()); } - static constexpr l_value_reference_forwarded_type forward(std::array&& value) { + static constexpr l_value_reference_forwarded_type + forward(std::array&& value) { return forward_impl(std::move(value), std::make_index_sequence()); } }; template using array_to_tuple_t = typename array_to_tuple::type; -template struct tuple_cat_type; +template struct tuple_cat_type; -template struct tuple_cat_type { - using type = typename tuple_cat_type::type>::type; +template struct tuple_cat_type { + using type = + typename tuple_cat_type::type>::type; }; -template struct tuple_cat_type, std::tuple> { - using type = std::tuple; +template +struct tuple_cat_type, std::tuple> { + using type = std::tuple; }; -template struct tuple_cat_type> { +template struct tuple_cat_type> { using type = std::tuple; }; -template <> struct tuple_cat_type<> { - using type = std::tuple<>; -}; +template <> struct tuple_cat_type<> { using type = std::tuple<>; }; // Forward as concatenated tuple template inline constexpr auto forward_as_reference_tuple(T const& value) - -> std::enable_if_t::value && !is_array::value, std::tuple> { + -> std::enable_if_t::value && !is_array::value, + std::tuple> { return std::tuple(value); } template -inline constexpr auto forward_as_reference_tuple(std::tuple const& value, - std::index_sequence) +inline constexpr auto +forward_as_reference_tuple(std::tuple const& value, + std::index_sequence) -> decltype(std::tuple_cat( forward_as_reference_tuple(std::get(value))...)); template inline constexpr auto forward_as_reference_tuple(std::tuple const& value) -> decltype(forward_as_reference_tuple(value, - std::index_sequence_for())); + std::index_sequence_for())); template -inline constexpr auto forward_as_reference_tuple(std::array const& value, - std::index_sequence) - -> decltype(std::tuple_cat(forward_as_reference_tuple(value[Indexes])...)); +inline constexpr auto +forward_as_reference_tuple(std::array const& value, + std::index_sequence) + -> decltype(std::tuple_cat(forward_as_reference_tuple(value[Indexes])...)); // -> decltype( // std::tuple_cat(forward_as_reference_tuple(value[Indexes])...)); template inline constexpr auto forward_as_reference_tuple(std::array const& value) --> decltype(forward_as_reference_tuple(value, std::make_index_sequence())); + -> decltype(forward_as_reference_tuple(value, + std::make_index_sequence())); /*template inline auto forward_as_reference_tuple(std::array const& value) - -> decltype(forward_as_reference_tuple(typename array_to_tuple>::const_l_value_reference_forwarded_type));*/ + -> decltype(forward_as_reference_tuple(typename array_to_tuple>::const_l_value_reference_forwarded_type));*/ template -inline constexpr auto forward_as_reference_tuple(std::tuple const& value, - std::index_sequence) +inline constexpr auto +forward_as_reference_tuple(std::tuple const& value, + std::index_sequence) -> decltype(std::tuple_cat( forward_as_reference_tuple(std::get(value))...)) { return std::tuple_cat( @@ -276,32 +297,35 @@ inline constexpr auto forward_as_reference_tuple(std::tuple const& value, template inline constexpr auto forward_as_reference_tuple(std::tuple const& value) - -> decltype(forward_as_reference_tuple( - value, std::index_sequence_for())) { + -> decltype(forward_as_reference_tuple(value, + std::index_sequence_for())) { return forward_as_reference_tuple(value, std::index_sequence_for()); } template -inline constexpr auto forward_as_reference_tuple(std::array const& value, - std::index_sequence) - -> decltype(std::tuple_cat(forward_as_reference_tuple(value[Indexes])...)) -{ +inline constexpr auto +forward_as_reference_tuple(std::array const& value, + std::index_sequence) + -> decltype(std::tuple_cat(forward_as_reference_tuple(value[Indexes])...)) { return std::tuple_cat(forward_as_reference_tuple(value[Indexes])...); } -// -> decltype(std::tuple_cat(forward_as_reference_tuple(value[Indexes])...)) { +// -> decltype(std::tuple_cat(forward_as_reference_tuple(value[Indexes])...)) +// { // return std::tuple_cat(forward_as_reference_tuple(value[Indexes])...); //} template inline constexpr auto forward_as_reference_tuple(std::array const& value) --> decltype(forward_as_reference_tuple(value, std::make_index_sequence())) { + -> decltype(forward_as_reference_tuple(value, + std::make_index_sequence())) { return forward_as_reference_tuple(value, std::make_index_sequence()); } /*template inline auto forward_as_reference_tuple(std::array const& value) - -> decltype(forward_as_reference_tuple(typename array_to_tuple>::const_l_value_reference_forwarded_type)) { - return forward_as_reference_tuple(array_to_tuple>::forward(value)); + -> decltype(forward_as_reference_tuple(typename array_to_tuple>::const_l_value_reference_forwarded_type)) { return +forward_as_reference_tuple(array_to_tuple>::forward(value)); }*/ } // namespace named_types diff --git a/includes/named_types/literals/integral_string_literal.hpp b/includes/named_types/literals/integral_string_literal.hpp index 7f75378..8646b7c 100644 --- a/includes/named_types/literals/integral_string_literal.hpp +++ b/includes/named_types/literals/integral_string_literal.hpp @@ -1,16 +1,15 @@ #pragma once #include "string_literal.hpp" -#include -#include #include +#include +#include namespace named_types { namespace arithmetic { - template constexpr T pow(T value, size_t power) { - static_assert(std::is_unsigned::value,"Type used must be unsigned"); + static_assert(std::is_unsigned::value, "Type used must be unsigned"); T current_value = 1; for (size_t index = 0; index < power; ++index) current_value *= value; @@ -18,7 +17,7 @@ template constexpr T pow(T value, size_t power) { } template constexpr size_t max_pow_holdable(T base, T value) { - static_assert(std::is_unsigned::value,"Type used must be unsigned"); + static_assert(std::is_unsigned::value, "Type used must be unsigned"); T current_value = value; size_t current_pow = 0; while (base <= current_value) { @@ -30,122 +29,146 @@ template constexpr size_t max_pow_holdable(T base, T value) { return current_pow; } -} // namespace arithmetic - +} // namespace arithmetic /** * This class represents */ -template class integral_string_format { +template +class integral_string_format { // Compute size storable - init part static constexpr size_t max_size_storable() { - return arithmetic::max_pow_holdable(sizeof ... (charset), std::numeric_limits::max()); + return arithmetic::max_pow_holdable( + sizeof...(charset), std::numeric_limits::max()); } -# ifndef _MSC_VER - template static constexpr size_t index_of(Char const (&input)[Size], size_t index, Char value) { - return (Size <= index) ? Size : ((input[index] == value) ? index : index_of(input,index+1,value)); +#ifndef _MSC_VER + template + static constexpr size_t + index_of(Char const (&input)[Size], size_t index, Char value) { + return (Size <= index) + ? Size + : ((input[index] == value) ? index + : index_of(input, index + 1, value)); } -# else +#else // MSVC does not support arrays in constexpr static constexpr size_t index_of(Char value, size_t index, size_t size) { return size; } - template static constexpr size_t index_of(Char value, size_t index, size_t size, Head current, Tail ... tail) { - return (index < size && value == current) ? index : index_of(value,index+1,size, tail...); + template + static constexpr size_t + index_of(Char value, size_t index, size_t size, Head current, Tail... tail) { + return (index < size && value == current) + ? index + : index_of(value, index + 1, size, tail...); } -# endif +#endif // Returns the index of the given char into the charset static constexpr size_t index_of(Char value) { -# ifndef _MSC_VER - return index_of({charset...},0u,value); -# else +#ifndef _MSC_VER + return index_of({charset...}, 0u, value); +#else // MSVC does not support arrays in constexpr - return index_of(value, 0u, sizeof ... (charset), charset ...); -# endif + return index_of(value, 0u, sizeof...(charset), charset...); +#endif } // Return true if the given char is included in the charset static constexpr bool contains(Char value) { - return index_of(value) < sizeof ... (charset); + return index_of(value) < sizeof...(charset); } - static constexpr Storage encode_impl(Char const* input, size_t current_index, size_t input_size) { + static constexpr Storage + encode_impl(Char const* input, size_t current_index, size_t input_size) { size_t value = 0; for (size_t index = 0; index < input_size; ++index) { - value += index_of(input[index])*arithmetic::pow(sizeof ... (charset), index); + value += + index_of(input[index]) * arithmetic::pow(sizeof...(charset), index); } return value; } static constexpr size_t decode_size(Storage input) { size_t index = 0; - for(;arithmetic::pow(sizeof ... (charset),index) < input; ++index); + for (; arithmetic::pow(sizeof...(charset), index) < input; ++index) + ; return index; } -# ifndef _MSC_VER - template static constexpr Char char_at_impl(Char const (&input)[Size], size_t index) { +#ifndef _MSC_VER + template + static constexpr Char char_at_impl(Char const (&input)[Size], size_t index) { return index < Size ? input[index] : 0u; } -# else +#else // MSVC does not support arrays in constexpr static constexpr Char char_at_impl(size_t current_index, size_t index) { return 0u; } - template static constexpr Char char_at_impl(size_t current_index, size_t index, Head current, Tail ... tail) { - return current_index == index ? current : char_at_impl(current_index+1u, index, tail...); + template + static constexpr Char + char_at_impl(size_t current_index, size_t index, Head current, Tail... tail) { + return current_index == index + ? current + : char_at_impl(current_index + 1u, index, tail...); } -# endif +#endif // Returns the char at position "index" in the charset static constexpr Char char_at(size_t index) { -# ifndef _MSC_VER - return char_at_impl({charset...},index); -# else +#ifndef _MSC_VER + return char_at_impl({charset...}, index); +#else // MSVC does not support arrays in constexpr return char_at_impl(0u, index, charset...); -# endif +#endif } - // Returns the charset index of the char encoded at pose "index" in the input encoded string + // Returns the charset index of the char encoded at pose "index" in the input + // encoded string static constexpr size_t decode_char_index_at(Storage input, size_t index) { - return 0u < input ? ((input-1u) / arithmetic::pow(sizeof ... (charset),index)) % sizeof ... (charset): sizeof ... (charset); + return 0u < input + ? ((input - 1u) / arithmetic::pow(sizeof...(charset), index)) % + sizeof...(charset) + : sizeof...(charset); } // Returns the char encoded at position "index" in the input encoded string static constexpr Char decode_char_at(Storage input, size_t index) { - return char_at(decode_char_index_at(input,index)); + return char_at(decode_char_index_at(input, index)); } - + template struct decode_impl; - template struct decode_impl,value> { - using type = string_literal; + template + struct decode_impl, value> { + using type = string_literal; }; public: - using string_literal_type = string_literal; + using string_literal_type = string_literal; -# ifdef _MSC_VER -# pragma warning(disable:4307) -# endif +#ifdef _MSC_VER +#pragma warning(disable : 4307) +#endif static constexpr size_t max_length_value = max_size_storable(); -# ifdef _MSC_VER -# pragma warning(default:4307) -# endif +#ifdef _MSC_VER +#pragma warning(default : 4307) +#endif // Encodes a string -# ifndef _MSC_VER - template static constexpr Storage encode(Char const (&input)[Size]) { - return encode(input,Size-1); // Be careful to exclude '\0' +#ifndef _MSC_VER + template + static constexpr Storage encode(Char const (&input)[Size]) { + return encode(input, Size - 1); // Be careful to exclude '\0' } -# endif +#endif static constexpr Storage encode(Char const* input, size_t input_size) { - return 0u == input_size ? 0u : encode_impl(input,0,input_size)+1; + return 0u == input_size ? 0u : encode_impl(input, 0, input_size) + 1; } static constexpr Storage encode(Char const* input) { @@ -154,24 +177,223 @@ template class integral_string_for // Decode an encoded string template struct decode { - using type = typename decode_impl, value>::type; + using type = typename decode_impl< + std::make_integer_sequence, + value>::type; }; }; // Providing built-in charsets -template using basic_charset = integral_string_format; -template using basic_lowcase_charset = integral_string_format; -template using ascii_charset = integral_string_format; +template +using basic_charset = integral_string_format; +template +using basic_lowcase_charset = integral_string_format; +template +using ascii_charset = integral_string_format; // Providing standard compliant formats using basic_charset_format = basic_charset; using basic_lowcase_charset_format = basic_lowcase_charset; using ascii_charset_format = ascii_charset; -}; // namespace named_types +}; // namespace named_types diff --git a/includes/named_types/literals/string_literal.hpp b/includes/named_types/literals/string_literal.hpp index b0150a3..4303ebb 100644 --- a/includes/named_types/literals/string_literal.hpp +++ b/includes/named_types/literals/string_literal.hpp @@ -1,7 +1,9 @@ #pragma once +#include "string_literal.hpp" #include #include -#include "string_literal.hpp" +#include +#include namespace named_types { @@ -12,10 +14,9 @@ unsigned long long constexpr const_size(Char const* input) { template unsigned long long constexpr const_hash(Char const* input) { - return *input - ? static_cast(*input) + - 33llu * const_hash(input + 1llu) - : 5381llu; + return *input ? static_cast(*input) + + 33llu * const_hash(input + 1llu) + : 5381llu; } #ifndef _MSC_VER @@ -29,19 +30,18 @@ unsigned long long constexpr array_const_hash() { return 5381llu; } template unsigned long long constexpr array_const_hash(Head current, Tail... tail) { - return 0u != current - ? static_cast(current) + - 33llu * array_const_hash(tail...) - : 5381llu; + return 0u != current ? static_cast(current) + + 33llu * array_const_hash(tail...) + : 5381llu; } #endif template struct string_literal { - static const char data[sizeof...(chars)+1u]; + static const char data[sizeof...(chars) + 1u]; static const size_t data_size = sizeof...(chars); #ifndef _MSC_VER static const unsigned long long hash_value = - array_const_hash({chars..., '\0'}); + array_const_hash({chars..., '\0'}); #else #pragma warning(disable : 4307) static const unsigned long long hash_value = array_const_hash(chars..., '\0'); @@ -70,8 +70,8 @@ template struct string_literal { }; template -const char string_literal::data[sizeof...(chars)+1u] = {chars..., - '\0'}; +const char string_literal::data[sizeof...(chars) + 1u] = {chars..., + '\0'}; // concatenate @@ -140,8 +140,9 @@ struct repeat_string<0u, string_literal> { template struct repeat_string> { - using type = concatenate_t < string_literal, - typename repeat_string>::type>; + using type = concatenate_t< + string_literal, + typename repeat_string>::type>; }; template @@ -149,8 +150,8 @@ using repeat_string_t = typename repeat_string::type; // join_repeat -template struct join_repeat_string; - +template +struct join_repeat_string; template struct join_repeat_string<0u, CharT, Glue, string_literal> { @@ -159,16 +160,21 @@ struct join_repeat_string<0u, CharT, Glue, string_literal> { template struct join_repeat_string<1u, CharT, Glue, string_literal> { - using type = string_literal; + using type = string_literal; }; template struct join_repeat_string> { - using type = concatenate_t , - typename join_repeat_string>::type>; + using type = concatenate_t< + string_literal, + typename join_repeat_string>::type>; }; template -using join_repeat_string_t = typename join_repeat_string::type; +using join_repeat_string_t = + typename join_repeat_string::type; -} // namespace string_literal +} // namespace named_types diff --git a/includes/named_types/named_tag.hpp b/includes/named_types/named_tag.hpp index 73b8362..2dfa0c9 100644 --- a/includes/named_types/named_tag.hpp +++ b/includes/named_types/named_tag.hpp @@ -1,7 +1,7 @@ #pragma once #include "literals/string_literal.hpp" -#include #include +#include namespace named_types { diff --git a/includes/named_types/named_tuple.hpp b/includes/named_types/named_tuple.hpp index 9166d1a..f5f54e4 100644 --- a/includes/named_types/named_tuple.hpp +++ b/includes/named_types/named_tuple.hpp @@ -1,8 +1,8 @@ #pragma once -#include -#include -#include #include "named_tag.hpp" +#include +#include +#include namespace named_types { @@ -27,10 +27,58 @@ template struct __ntuple_tag_notation { template using __ntuple_tag_notation_t = typename __ntuple_tag_notation::type; +// forward declaration +template struct named_tuple; + +} // namespace named_types + +// Standard specialization + +namespace std { + +template +struct tuple_element> { + using type = + tuple_element_t...>>; +}; + +template +inline constexpr + typename tuple_element>::type& + get(named_types::named_tuple& in) { + return get( + static_cast::tuple_type&>(in)); +} + +template +inline constexpr const typename tuple_element< + Index, + named_types::named_tuple>::type& +get(const named_types::named_tuple& in) { + return get( + static_cast< + const typename named_types::named_tuple::tuple_type&>(in)); +} + +template +inline constexpr + typename tuple_element>::type&& + get(named_types::named_tuple&& in) { + return move(get( + static_cast::tuple_type&&>( + in))); +} + +} // namespace std + +// end Standard specialization + +namespace named_types { + template struct named_tuple : public std::tagged_tuple<__ntuple_tag_notation_t...> - // struct named_tuple : std::tagged_tuple< Types ... - { +// struct named_tuple : std::tagged_tuple< Types ... +{ // Type aliases using tuple_type = std::tuple<__ntuple_tag_elem_t...>; using tagged_type = std::tagged_tuple<__ntuple_tag_notation_t...>; @@ -73,10 +121,9 @@ struct named_tuple : public std::tagged_tuple<__ntuple_tag_notation_t...> } template - inline typename std::enable_if_t< - tag_not_assignable_from::value, - Value> - ctor_assign_from(ForeignTuple const& from) { + inline typename std:: + enable_if_t::value, Value> + ctor_assign_from(ForeignTuple const& from) { return {}; } @@ -166,7 +213,7 @@ struct named_tuple : public std::tagged_tuple<__ntuple_tag_notation_t...> // Member operator [] template - inline decltype(auto) operator[](named_tag const&)& { + inline decltype(auto) operator[](named_tag const&) & { return std::get< named_tuple::template tag_index::type>::value>( *this); @@ -180,7 +227,7 @@ struct named_tuple : public std::tagged_tuple<__ntuple_tag_notation_t...> } template - inline decltype(auto) operator[](named_tag const&)&& { + inline decltype(auto) operator[](named_tag const&) && { return std::get< named_tuple::template tag_index::type>::value>( std::move(*this)); @@ -200,27 +247,17 @@ inline constexpr decltype(auto) make_named_tuple(Types&&... args) { template inline constexpr void for_each(Func&& f, named_tuple const& in) { using swallow = int[]; - (void)swallow{ - int{}, - (f(__ntuple_tag_spec_t{}, get<__ntuple_tag_spec_t>(in)), - int{})...}; + (void)swallow{int{}, (f(__ntuple_tag_spec_t{}, + get<__ntuple_tag_spec_t>(in)), + int{})...}; } // apply : should be replaceable by std::experimental::apply template -inline constexpr auto apply(Func&& f, named_tuple const& in) -> decltype(auto) { +inline constexpr auto apply(Func&& f, named_tuple const& in) + -> decltype(auto) { return f(get<__ntuple_tag_spec_t>(in)...); } } // namespace named_types - -// Standard specialization - -namespace std { -template -struct tuple_element> { - using type = - tuple_element_t...>>; -}; -} // namespace std diff --git a/includes/named_types/rt_named_tag.hpp b/includes/named_types/rt_named_tag.hpp index a12830c..0286d03 100644 --- a/includes/named_types/rt_named_tag.hpp +++ b/includes/named_types/rt_named_tag.hpp @@ -1,6 +1,6 @@ #pragma once -#include #include "named_tag.hpp" +#include namespace named_types { // Named extraction for runtime default naming @@ -21,7 +21,7 @@ template class type_name { static inline auto extract(int) -> decltype(TT::name()) { return TT::name(); } - template static inline auto extract(...) -> char const * { + template static inline auto extract(...) -> char const* { return typeid(TT).name(); } #endif // _MSC_VER diff --git a/includes/named_types/rt_named_tuple.hpp b/includes/named_types/rt_named_tuple.hpp index 2b524d7..21c39c2 100644 --- a/includes/named_types/rt_named_tuple.hpp +++ b/includes/named_types/rt_named_tuple.hpp @@ -1,8 +1,8 @@ #pragma once #include "named_tuple.hpp" #include "rt_named_tag.hpp" -#include #include +#include namespace named_types { @@ -80,10 +80,11 @@ std::array const {&typeid(__ntuple_tag_elem_t)...}}; template -std::array const - const_rt_view_impl>::attributes = { - {std::string(type_name< - typename __ntuple_tag_spec_t::value_type>::value)...}}; +std::array const const_rt_view_impl< + Parent, + named_tuple>::attributes = { + {std::string( + type_name::value_type>::value)...}}; // Non-const version template diff --git a/includes/std/experimental/tagged.hpp b/includes/std/experimental/tagged.hpp index cb70bdf..33f465e 100644 --- a/includes/std/experimental/tagged.hpp +++ b/includes/std/experimental/tagged.hpp @@ -16,10 +16,10 @@ #ifndef SDT_EXPERIMENTAL_TAGGED_HEADER #define SDT_EXPERIMENTAL_TAGGED_HEADER -#include #include #include #include +#include namespace std { template struct tagged; @@ -56,6 +56,7 @@ struct __getters { template struct tagged : Base, __getters::collect, Tags...> { using Base::Base; + using base_tuple = Base; tagged() = default; tagged(tagged&&) = default; tagged(const tagged&) = default; @@ -119,9 +120,7 @@ struct __indexes { template struct collect_, Types...> - : tag_indexer_<__tag_spec_t, - __tag_elem_t, - Is>... { + : tag_indexer_<__tag_spec_t, __tag_elem_t, Is>... { constexpr collect_(){}; ~collect_() = default; constexpr collect_(const collect_&) = default; @@ -161,8 +160,9 @@ struct __indexes { } template - static constexpr typename tag_indexer_:: - tag_index permissive_get_tag_index(...) { + static constexpr + typename tag_indexer_::tag_index + permissive_get_tag_index(...) { return {}; } @@ -191,7 +191,7 @@ struct __indexes { template static constexpr tag_indexer_ - permissive_get_tag_indexer(...) { + permissive_get_tag_indexer(...) { return {}; } @@ -211,14 +211,13 @@ struct indexed_tagged }; template -using tagged_pair = - tagged, __tag_elem_t>, - __tag_spec_t, - __tag_spec_t>; +using tagged_pair = tagged, __tag_elem_t>, + __tag_spec_t, + __tag_spec_t>; template using __tagged_tuple = - indexed_tagged::type ... >, Types...>; + indexed_tagged::type...>, Types...>; /** * Making tagged_tuple a new type is mandatory to make @@ -231,20 +230,22 @@ template struct tagged_tuple : __tagged_tuple { template typename tagged_tuple::template type_at::raw_type const& get(tagged_tuple const& input) { - return get::template tag_index::value>(input); + return get::template tag_index::value>( + static_cast::base_tuple const&>(input)); }; template typename tagged_tuple::template type_at::raw_type& get(tagged_tuple& input) { - return get::template tag_index::value>(input); + return get::template tag_index::value>( + static_cast::base_tuple&>(input)); }; template typename tagged_tuple::template type_at::raw_type&& get(tagged_tuple&& input) { - return move(get::template tag_index::value>( - std::forward>(input))); + return get::template tag_index::value>( + static_cast::base_tuple&&>(input)); }; namespace tag { @@ -260,12 +261,12 @@ struct basic_tag { ~getter() = default; private: - friend struct __getters; + friend struct std::__getters; }; - friend struct __getters; + friend struct std::__getters; }; -} -} +} // namespace tag +} // namespace std #endif // SDT_EXPERIMENTAL_TAGGED_HEADER