-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
51 lines (39 loc) · 1.14 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
/*
* main.cpp
*
* Created on: 17 Jun 2019
* Author: UncleAnti
*/
#include "semisplit.h"
#include <vector>
#include <algorithm>
#include <fmt/core.h>
#include <fmt/format.h>
#define SplitContainer std::vector
#define SampleContainer std::vector<int>
template <> struct fmt::formatter<SampleContainer> {
constexpr auto parse(format_parse_context& ctx) -> decltype(ctx.begin()) {
return ctx.begin();
}
template <typename FormatContext>
auto format(const SampleContainer& arg, FormatContext& ctx) -> decltype(ctx.out()) {
std::string output;
for (const auto &it : arg)
output += fmt::format("{:3},", it);
if (!output.empty())
output.resize(output.size()-1);
return format_to(ctx.out(), "[{}]", output);
}
};
int main() {
SampleContainer sample { 0,4,7,9,12,13,14,20 };
auto results = SemiSplit<SplitContainer>(sample);
// auto results = SemiSplit(sample);
fmt::print("Sample[{}] = {}\n", sample.size(), sample);
std::string output;
for (const auto & first : results)
output += fmt::format("{},", first);
if (!output.empty())
output.resize(output.size()-1);
fmt::print("Output[{}] = [{}]\n", results.size(), output);
}