add within
This commit is contained in:
parent
d7bff82e02
commit
55a2bacc0e
@ -1,11 +1,17 @@
|
||||
#include <iostream>
|
||||
|
||||
#include "string/string.hpp"
|
||||
#include "range/range.hpp"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
{// ex: split_str
|
||||
std::string str { "asdf,qwer,zxcv" };
|
||||
hack::v_str v = hack::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;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
deps += string_dep
|
||||
deps += range_dep
|
||||
|
||||
executable(
|
||||
'hack', 'main.cpp',
|
||||
|
@ -1,3 +1,4 @@
|
||||
inc += include_directories('.')
|
||||
|
||||
subdir('string')
|
||||
subdir('range')
|
||||
|
14
src/range/meson.build
Normal file
14
src/range/meson.build
Normal file
@ -0,0 +1,14 @@
|
||||
headers = ['range.hpp']
|
||||
sources = ['range.cpp']
|
||||
|
||||
lib = library(
|
||||
'range',
|
||||
include_directories : inc,
|
||||
install : true,
|
||||
sources: [headers, sources]
|
||||
)
|
||||
|
||||
range_dep = declare_dependency(
|
||||
include_directories: inc,
|
||||
link_with: lib
|
||||
)
|
5
src/range/range.cpp
Normal file
5
src/range/range.cpp
Normal file
@ -0,0 +1,5 @@
|
||||
#include "range.hpp"
|
||||
|
||||
namespace hack
|
||||
{
|
||||
}
|
15
src/range/range.hpp
Normal file
15
src/range/range.hpp
Normal file
@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace hack
|
||||
{
|
||||
template<typename T, typename... Args>
|
||||
bool within(T min, T max, Args... args)
|
||||
{
|
||||
return ((min <= args && max >= args) && ...);
|
||||
// 1, 5, 2, 3, 4
|
||||
// ( (1 <= 2 && 5 >= 2) && (1 <= 3 && 5 >= 3) && (1 <= 4 && 5 >= 4) )
|
||||
}
|
||||
}
|
@ -5,7 +5,16 @@ test(
|
||||
'split_str',
|
||||
executable(
|
||||
'split_str',
|
||||
'split_str.cpp',
|
||||
'string.cpp',
|
||||
dependencies: [ string_dep, gtest_dep ]
|
||||
)
|
||||
)
|
||||
|
||||
test(
|
||||
'within',
|
||||
executable(
|
||||
'within',
|
||||
'range.cpp',
|
||||
dependencies: [ range_dep, gtest_dep ]
|
||||
)
|
||||
)
|
||||
|
9
tests/range.cpp
Normal file
9
tests/range.cpp
Normal file
@ -0,0 +1,9 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "range/range.hpp"
|
||||
|
||||
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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user