diff --git a/CMakeLists.txt b/CMakeLists.txt index 346012a..e48a684 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,13 +28,13 @@ set(NAMED_HEADERS include/Named/NamedTuple.hpp include/Named/TaggedArray.hpp include/Named/TaggedBitset.hpp + include/Named/detail/Common.hpp include/Named/detail/NamedTupleUtil.hpp include/Named/detail/StringLiteral.hpp include/Named/detail/SynthThreeWayResult.hpp ) -add_library(named INTERFACE - include/Named/detail/Common.hpp) +add_library(named INTERFACE) target_include_directories(named INTERFACE include) target_sources(named INTERFACE ${NAMED_HEADERS}) set_target_properties(named PROPERTIES LINKER_LANGUAGE CXX) @@ -58,9 +58,5 @@ if (NAMED_BUILD_TESTS) COMMAND sample) endif () - find_package(Catch2 COMPONENTS Catch2WithMain) - - if (Catch2_FOUND) - add_subdirectory(test) - endif () + add_subdirectory(test) endif () diff --git a/conanfile.py b/conanfile.py index a910c6c..c356e55 100644 --- a/conanfile.py +++ b/conanfile.py @@ -7,7 +7,7 @@ class NamedConan(ConanFile): name = 'named' - version = '0.0.2' + version = '0.0.4' license = 'MIT' author = 'Matthew Guidry' diff --git a/include/Named/NamedTuple.hpp b/include/Named/NamedTuple.hpp index bcd8c75..ca5f69a 100644 --- a/include/Named/NamedTuple.hpp +++ b/include/Named/NamedTuple.hpp @@ -101,7 +101,7 @@ struct NamedTuple : std::tuple::type...> { /** * @brief Extracts the element of the NamedTuple whose name is Tag - * @tparam Tag a StringLiteral to search for + * @tparam Tag Name of the element in the NamedTuple to get * @return the element of the NamedTuple whose name is Tag */ template @@ -113,7 +113,7 @@ struct NamedTuple : std::tuple::type...> { /** * @brief Extracts the element of the NamedTuple whose name is Tag - * @tparam Tag a StringLiteral to search for + * @tparam Tag Name of the element in the NamedTuple to get * @return the element of the NamedTuple whose name is Tag */ template @@ -125,7 +125,7 @@ struct NamedTuple : std::tuple::type...> { /** * @brief Extracts the element of the NamedTuple whose name is Tag - * @tparam Tag a StringLiteral to search for + * @tparam Tag Name of the element in the NamedTuple to get * @return the element of the NamedTuple whose name is Tag */ template @@ -137,7 +137,7 @@ struct NamedTuple : std::tuple::type...> { /** * @brief Extracts the element of the NamedTuple whose name is Tag - * @tparam Tag a StringLiteral to search for + * @tparam Tag Name of the element in the NamedTuple to get * @return the element of the NamedTuple whose name is Tag */ template diff --git a/include/Named/detail/Common.hpp b/include/Named/detail/Common.hpp index e4f70e0..78473ce 100644 --- a/include/Named/detail/Common.hpp +++ b/include/Named/detail/Common.hpp @@ -87,7 +87,7 @@ constexpr std::size_t reverse_index_in_pack() { * @return true if all values in the pack are unique; otherwise false */ template -constexpr bool all_unique_nttps() { +consteval bool all_unique_nttps() { if constexpr (sizeof...(Nttps) == 0) { return true; } else { diff --git a/source/sample/main.cpp b/source/sample/main.cpp index 209bcee..1789d4d 100644 --- a/source/sample/main.cpp +++ b/source/sample/main.cpp @@ -10,18 +10,18 @@ using mguid::NamedTypeV; int main() { int i = 5; - std::reference_wrapper i_ref{i}; + const std::reference_wrapper i_ref{i}; const auto nt = mguid::make_tuple(NamedTypeV<"int_key">(i_ref), NamedTypeV<"float_key">(1.0f), NamedTypeV<"char_key">('c')); mguid::apply( [](const auto&&... args) { - std::cout << "("; + std::cout << "{"; std::size_t count{1}; - ((std::cout << "{" << args.first.view() << ":" << args.second - << ((count++ != sizeof...(args)) ? "}," : "}")), + ((std::cout << args.first.view() << ":" << args.second + << ((count++ != sizeof...(args)) ? "," : "")), ...); - std::cout << ")"; + std::cout << "}\n"; }, nt); @@ -29,6 +29,10 @@ int main() { std::cout << nt.get<"float_key">() << '\n'; std::cout << nt.get<"char_key">() << '\n'; + std::cout << nt.get<0>() << '\n'; + std::cout << nt.get<1>() << '\n'; + std::cout << nt.get<2>() << '\n'; + std::cout << mguid::get<"int_key">(nt) << '\n'; std::cout << mguid::get<"float_key">(nt) << '\n'; std::cout << mguid::get<"char_key">(nt) << '\n'; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 11fbc62..1db1c9b 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,15 +1,20 @@ -set(UNIT_TEST_SRC - unit_test_named_tuple.cpp - unit_test_tagged_bitset.cpp - unit_test_tagged_array.cpp -) +find_package(Catch2 COMPONENTS Catch2WithMain) -add_executable(unit_tests) -target_sources(unit_tests PRIVATE ${UNIT_TEST_SRC}) -target_link_libraries(unit_tests PRIVATE named Catch2::Catch2WithMain) +if (Catch2_FOUND) + set(UNIT_TEST_SRC + unit_test_named_tuple.cpp + unit_test_tagged_bitset.cpp + unit_test_tagged_array.cpp + ) -enable_testing() + add_executable(unit_tests) + target_sources(unit_tests PRIVATE ${UNIT_TEST_SRC}) + target_link_libraries(unit_tests PRIVATE named Catch2::Catch2 Catch2::Catch2WithMain) + + enable_testing() + + add_test(NAME unit_tests + WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} + COMMAND unit_tests) +endif () -add_test(NAME unit_tests - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} - COMMAND unit_tests)