add container v_multiset
This commit is contained in:
parent
3148ecd29e
commit
9d3c2a4153
11
bin/main.cpp
11
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<std::string> v;
|
||||
hack::container::v_multiset(v, "asdf", "qwer", "zcv");
|
||||
for(const auto& c : v) std::cout << c << std::endl;
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
deps += string_dep
|
||||
deps += range_dep
|
||||
deps += range_dep
|
||||
|
||||
executable(
|
||||
'hack', 'main.cpp',
|
||||
|
5
src/container/container.cpp
Normal file
5
src/container/container.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "container.hpp"
|
||||
|
||||
namespace hack::container
|
||||
{
|
||||
}
|
14
src/container/container.hpp
Normal file
14
src/container/container.hpp
Normal file
@ -0,0 +1,14 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace hack::container
|
||||
{
|
||||
template<typename Range, typename... Args>
|
||||
void v_multiset(Range& r, Args... args)
|
||||
{
|
||||
std::size_t t = sizeof... (args);
|
||||
r.reserve(t);
|
||||
(r.emplace_back(std::forward<Args>(args)), ...);
|
||||
}
|
||||
}
|
14
src/container/meson.build
Normal file
14
src/container/meson.build
Normal file
@ -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
|
||||
)
|
@ -2,3 +2,4 @@ inc += include_directories('.')
|
||||
|
||||
subdir('string')
|
||||
subdir('range')
|
||||
subdir('container')
|
||||
|
@ -1,5 +1,5 @@
|
||||
#include "range.hpp"
|
||||
|
||||
namespace hack
|
||||
namespace hack::renge
|
||||
{
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace hack
|
||||
namespace hack::range
|
||||
{
|
||||
template<typename T, typename... Args>
|
||||
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
|
||||
|
@ -1,6 +1,6 @@
|
||||
#include "string.hpp"
|
||||
|
||||
namespace hack
|
||||
namespace hack::string
|
||||
{
|
||||
v_str split_str(const std::string& str, char t)
|
||||
{
|
||||
|
@ -3,7 +3,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace hack
|
||||
namespace hack::string
|
||||
{
|
||||
using v_str = std::vector<std::string>;
|
||||
|
||||
|
10
tests/container.cpp
Normal file
10
tests/container.cpp
Normal file
@ -0,0 +1,10 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "container/container.hpp"
|
||||
|
||||
TEST(v_multiset, check)
|
||||
{
|
||||
std::vector<int> v;
|
||||
hack::container::v_multiset(v, 1, 2, 3);
|
||||
ASSERT_EQ(v.at(0), 1);
|
||||
}
|
@ -18,3 +18,12 @@ test(
|
||||
dependencies: [ range_dep, gtest_dep ]
|
||||
)
|
||||
)
|
||||
|
||||
test(
|
||||
'container',
|
||||
executable(
|
||||
'container',
|
||||
'container.cpp',
|
||||
dependencies: [ range_dep, gtest_dep ]
|
||||
)
|
||||
)
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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<std::string> v { "asdf", "qwer", "zxcv" };
|
||||
ASSERT_EQ(hack::string::split_str("asdf,qwer,zxcv", ','), v);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user