Add Tuple Example
This commit is contained in:
parent
8dedf835b6
commit
0c5d612867
2 changed files with 34 additions and 0 deletions
|
@ -18,4 +18,15 @@ if(ENABLE_TESTS)
|
|||
include(GoogleTest)
|
||||
gtest_discover_tests(utempl_tests)
|
||||
endif()
|
||||
if(ENABLE_EXAMPLES)
|
||||
file(GLOB EXAMPLES_SRC "examples/src/*.cpp")
|
||||
foreach(EXAMPLE_SRC ${EXAMPLES_SRC})
|
||||
get_filename_component(EXAMPLE_NAME ${EXAMPLE_SRC} NAME_WE)
|
||||
add_executable(${EXAMPLE_NAME} ${EXAMPLE_SRC})
|
||||
target_link_libraries(${EXAMPLE_NAME} utempl)
|
||||
set_property(TARGET ${EXAMPLE_NAME} PROPERTY CXX_STANDARD 20)
|
||||
set_target_properties(${EXAMPLE_NAME} PROPERTIES
|
||||
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/examples/")
|
||||
endforeach()
|
||||
endif()
|
||||
target_include_directories(utempl INTERFACE include)
|
||||
|
|
23
examples/src/tuple.cpp
Normal file
23
examples/src/tuple.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include <utempl/tuple.hpp>
|
||||
#include <utempl/utils.hpp>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
auto main() -> int {
|
||||
using utempl::literals::operator""_c;
|
||||
constexpr utempl::Tuple tuple = utempl::Tuple{42, 3.141500, "Hello World"};
|
||||
utempl::Tuple<int> tuple2{{}};
|
||||
std::ignore = tuple2;
|
||||
std::cout << utempl::kTupleSize<decltype(tuple)> << std::endl; // Get tuple size
|
||||
std::cout << tuple[0_c] << std::endl; // Get element using [] with literal
|
||||
auto newTuple = utempl::Transform(tuple, utempl::Overloaded(
|
||||
[](auto arg){
|
||||
return std::to_string(arg);
|
||||
},
|
||||
[](const char* arg) {
|
||||
return std::string(arg);
|
||||
}
|
||||
));
|
||||
auto flag = newTuple == utempl::Tuple<std::string, std::string, std::string>{"42", "3.141500", "Hello World"};
|
||||
assert(flag);
|
||||
};
|
Loading…
Reference in a new issue