Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 ()
2 changes: 1 addition & 1 deletion conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class NamedConan(ConanFile):
name = 'named'
version = '0.0.2'
version = '0.0.4'

license = 'MIT'
author = 'Matthew Guidry'
Expand Down
8 changes: 4 additions & 4 deletions include/Named/NamedTuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ struct NamedTuple : std::tuple<typename ExtractType<NamedTypes>::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 <StringLiteral Tag>
Expand All @@ -113,7 +113,7 @@ struct NamedTuple : std::tuple<typename ExtractType<NamedTypes>::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 <StringLiteral Tag>
Expand All @@ -125,7 +125,7 @@ struct NamedTuple : std::tuple<typename ExtractType<NamedTypes>::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 <StringLiteral Tag>
Expand All @@ -137,7 +137,7 @@ struct NamedTuple : std::tuple<typename ExtractType<NamedTypes>::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 <StringLiteral Tag>
Expand Down
2 changes: 1 addition & 1 deletion include/Named/detail/Common.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <auto... Nttps>
constexpr bool all_unique_nttps() {
consteval bool all_unique_nttps() {
if constexpr (sizeof...(Nttps) == 0) {
return true;
} else {
Expand Down
14 changes: 9 additions & 5 deletions source/sample/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,29 @@ using mguid::NamedTypeV;

int main() {
int i = 5;
std::reference_wrapper<int> i_ref{i};
const std::reference_wrapper<int> 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);

std::cout << nt.get<"int_key">() << '\n';
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';
Expand Down
29 changes: 17 additions & 12 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)