...
This commit is contained in:
47
examples/hvec_example.cpp
Normal file
47
examples/hvec_example.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
#include <print>
|
||||
#include <vector>
|
||||
|
||||
#include <snipplib/containers/snplib_hvec.h>
|
||||
|
||||
using namespace snplib;
|
||||
|
||||
struct visitor {
|
||||
using types = std::tuple<std::string, unsigned long>;
|
||||
|
||||
void operator()(auto& v)
|
||||
{
|
||||
using val_t = std::decay_t<decltype(v)>;
|
||||
|
||||
if constexpr (std::ranges::input_range<val_t>) {
|
||||
std::println("range val = {}", v);
|
||||
} else {
|
||||
std::println("val = {}", v);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
HeterogenVec vec;
|
||||
|
||||
vec.push(1.1);
|
||||
vec.push(std::string{"AAA"});
|
||||
vec.push(100UL);
|
||||
vec.push(200UL);
|
||||
vec.push(300UL);
|
||||
|
||||
std::vector<char> v{'q', 'w', 'e'};
|
||||
|
||||
vec.emplace<std::string>(std::from_range_t{}, v);
|
||||
|
||||
vec.visit(visitor{});
|
||||
vec.visitRange(visitor{});
|
||||
|
||||
vec.clear();
|
||||
|
||||
std::println("\n\tafter clear() ...");
|
||||
vec.visit(visitor{});
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user