forked from cirosantilli/cpp-cheat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (56 loc) · 1.84 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/**
General boost cheat. Libraries which are too large may be in different files.
*/
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <vector>
#include <boost/algorithm/string.hpp> // split
#include <boost/filesystem.hpp> // -lboost_filesystem -lsystem
#include <boost/iterator/counting_iterator.hpp>
#include <boost/range/algorithm/remove_if.hpp>
int main() {
// #counting_iterator
{
std::vector<int> v(boost::counting_iterator<int>(0), boost::counting_iterator<int>(3));
assert((v == std::vector<int>{0, 1, 2}));
}
//#string
{
// #split string into array of strings at a character.
{
std::vector<std::string> strs;
boost::split(strs, "a b\tcd", boost::is_any_of("\t "));
assert((strs == std::vector<std::string>{"a", "", "b", "cd"}));
}
// # strip
// #filter
{
// Single character, no single function in C++11.
{
std::string str = "a0bc00d";
boost::erase_all(str, "0");
assert((str == "abcd"));
}
// Any character from a string.
{
std::string str = "a_bc0_d";
str.erase(boost::remove_if(str, boost::is_any_of("_0")), str.end());
assert((str == "abcd"));
std::vector<int> is{0, 1, 2, 0, 3};
is.erase(boost::remove_if(is, boost::is_any_of(std::vector<int>{0, 2})), is.end());
assert((is == std::vector<int>{1, 3}));
}
}
}
/*
# filesystem
# path
# join
Proposed for inclusion on TR2.
*/
{
std::cout << "filesystem /tmp + foo.txt = " <<
boost::filesystem::path("/tmp") / boost::filesystem::path("foo.txt") << std::endl;
}
}