]>
Commit | Line | Data |
---|---|---|
1e59de90 TL |
1 | // Copyright 2015 Google Inc. All rights reserved. |
2 | // | |
3 | // Licensed under the Apache License, Version 2.0 (the "License"); | |
4 | // you may not use this file except in compliance with the License. | |
5 | // You may obtain a copy of the License at | |
6 | // | |
7 | // http://www.apache.org/licenses/LICENSE-2.0 | |
8 | // | |
9 | // Unless required by applicable law or agreed to in writing, software | |
10 | // distributed under the License is distributed on an "AS IS" BASIS, | |
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 | // See the License for the specific language governing permissions and | |
13 | // limitations under the License. | |
14 | ||
15 | #include <benchmark/benchmark.h> | |
16 | ||
17 | namespace benchmark { | |
18 | ||
19 | namespace { | |
20 | ||
21 | // Compute the total size of a pack of std::strings | |
22 | size_t size_impl() { return 0; } | |
23 | ||
24 | template <typename Head, typename... Tail> | |
25 | size_t size_impl(const Head& head, const Tail&... tail) { | |
26 | return head.size() + size_impl(tail...); | |
27 | } | |
28 | ||
29 | // Join a pack of std::strings using a delimiter | |
30 | // TODO: use absl::StrJoin | |
31 | void join_impl(std::string&, char) {} | |
32 | ||
33 | template <typename Head, typename... Tail> | |
34 | void join_impl(std::string& s, const char delimiter, const Head& head, | |
35 | const Tail&... tail) { | |
36 | if (!s.empty() && !head.empty()) { | |
37 | s += delimiter; | |
38 | } | |
39 | ||
40 | s += head; | |
41 | ||
42 | join_impl(s, delimiter, tail...); | |
43 | } | |
44 | ||
45 | template <typename... Ts> | |
46 | std::string join(char delimiter, const Ts&... ts) { | |
47 | std::string s; | |
48 | s.reserve(sizeof...(Ts) + size_impl(ts...)); | |
49 | join_impl(s, delimiter, ts...); | |
50 | return s; | |
51 | } | |
52 | } // namespace | |
53 | ||
54 | std::string BenchmarkName::str() const { | |
55 | return join('/', function_name, args, min_time, iterations, repetitions, | |
56 | time_type, threads); | |
57 | } | |
58 | } // namespace benchmark |