diff --git a/bin/main.cpp b/bin/main.cpp index 3d9fc4e..65c21ce 100644 --- a/bin/main.cpp +++ b/bin/main.cpp @@ -2,16 +2,23 @@ #include "string/string.hpp" #include "range/range.hpp" +#include "container/container.hpp" int main(int argc, char *argv[]) { {// ex: split_str std::string str { "asdf,qwer,zxcv" }; - hack::v_str v = hack::split_str(str, ','); + hack::string::v_str v = hack::string::split_str(str, ','); for (const auto& c : v) std::cout << c << std::endl; } {// ex: within - std::cout << hack::within(12, 34, 12, 23, 31) << std::endl; + std::cout << std::boolalpha << hack::range::within(12, 34, 12, 23, 31, 17, 22, 33) << std::endl; + } + + {// ex: v_multiset + std::vector v; + hack::container::v_multiset(v, "asdf", "qwer", "zcv"); + for(const auto& c : v) std::cout << c << std::endl; } } diff --git a/bin/meson.build b/bin/meson.build index 6baa655..727a5f2 100644 --- a/bin/meson.build +++ b/bin/meson.build @@ -1,5 +1,6 @@ deps += string_dep deps += range_dep +deps += range_dep executable( 'hack', 'main.cpp', diff --git a/src/container/container.cpp b/src/container/container.cpp new file mode 100644 index 0000000..b9b67f4 --- /dev/null +++ b/src/container/container.cpp @@ -0,0 +1,5 @@ +#include "container.hpp" + +namespace hack::container +{ +} diff --git a/src/container/container.hpp b/src/container/container.hpp new file mode 100644 index 0000000..e88e14f --- /dev/null +++ b/src/container/container.hpp @@ -0,0 +1,14 @@ +#pragma once + +#include + +namespace hack::container +{ + template + void v_multiset(Range& r, Args... args) + { + std::size_t t = sizeof... (args); + r.reserve(t); + (r.emplace_back(std::forward(args)), ...); + } +} diff --git a/src/container/meson.build b/src/container/meson.build new file mode 100644 index 0000000..29d3539 --- /dev/null +++ b/src/container/meson.build @@ -0,0 +1,14 @@ +headers = ['container.hpp'] +sources = ['container.cpp'] + +lib = library( + 'container', + include_directories : inc, + install : true, + sources: [headers, sources] +) + +container_dep = declare_dependency( + include_directories: inc, + link_with: lib +) diff --git a/src/meson.build b/src/meson.build index 325ba16..2e0df30 100644 --- a/src/meson.build +++ b/src/meson.build @@ -2,3 +2,4 @@ inc += include_directories('.') subdir('string') subdir('range') +subdir('container') diff --git a/src/range/range.cpp b/src/range/range.cpp index 614e456..70dd2e8 100644 --- a/src/range/range.cpp +++ b/src/range/range.cpp @@ -1,5 +1,5 @@ #include "range.hpp" -namespace hack +namespace hack::renge { } diff --git a/src/range/range.hpp b/src/range/range.hpp index 82c93bb..a91f5fd 100644 --- a/src/range/range.hpp +++ b/src/range/range.hpp @@ -1,9 +1,9 @@ #pragma once -namespace hack +namespace hack::range { template - bool within(T min, T max, Args... args) + bool within(const T min, const T max, Args... args) { return ((min <= args && max >= args) && ...); // 1, 5, 2, 3, 4 diff --git a/src/string/string.cpp b/src/string/string.cpp index df3a2e5..b7c94d2 100644 --- a/src/string/string.cpp +++ b/src/string/string.cpp @@ -1,6 +1,6 @@ #include "string.hpp" -namespace hack +namespace hack::string { v_str split_str(const std::string& str, char t) { diff --git a/src/string/string.hpp b/src/string/string.hpp index 6b4a87a..81d21be 100644 --- a/src/string/string.hpp +++ b/src/string/string.hpp @@ -3,7 +3,7 @@ #include #include -namespace hack +namespace hack::string { using v_str = std::vector; diff --git a/tests/container.cpp b/tests/container.cpp new file mode 100644 index 0000000..7895080 --- /dev/null +++ b/tests/container.cpp @@ -0,0 +1,10 @@ +#include + +#include "container/container.hpp" + +TEST(v_multiset, check) +{ + std::vector v; + hack::container::v_multiset(v, 1, 2, 3); + ASSERT_EQ(v.at(0), 1); +} diff --git a/tests/meson.build b/tests/meson.build index 9773ccb..24775e3 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -18,3 +18,12 @@ test( dependencies: [ range_dep, gtest_dep ] ) ) + +test( + 'container', + executable( + 'container', + 'container.cpp', + dependencies: [ range_dep, gtest_dep ] + ) +) diff --git a/tests/range.cpp b/tests/range.cpp index 10edac8..4066e39 100644 --- a/tests/range.cpp +++ b/tests/range.cpp @@ -4,6 +4,6 @@ TEST(within, check) { - ASSERT_EQ(hack::within(23, 123, 34, 44, 55, 66), true); - ASSERT_EQ(hack::within(23, 123, 134, 44, 55, 66), false); + ASSERT_EQ(hack::range::within(23, 123, 34, 44, 55, 66), true); + ASSERT_EQ(hack::range::within(23, 123, 134, 44, 55, 66), false); } diff --git a/tests/string.cpp b/tests/string.cpp index e644003..0cffff2 100644 --- a/tests/string.cpp +++ b/tests/string.cpp @@ -7,7 +7,6 @@ TEST(split_str, check) { - hack::v_str v { "asdf", "qwer", "zxcv" }; - - ASSERT_EQ(hack::split_str("asdf,qwer,zxcv", ','), v); + std::vector v { "asdf", "qwer", "zxcv" }; + ASSERT_EQ(hack::string::split_str("asdf,qwer,zxcv", ','), v); }