60 lines · plain
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 at6//7// http://www.apache.org/licenses/LICENSE-2.08//9// Unless required by applicable law or agreed to in writing, software10// 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 and13// limitations under the License.14 15#include <benchmark/benchmark.h>16 17namespace benchmark {18 19namespace {20 21// Compute the total size of a pack of std::strings22size_t size_impl() { return 0; }23 24template <typename Head, typename... Tail>25size_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 delimiter30// TODO: use absl::StrJoin31void join_impl(std::string&, char) {}32 33template <typename Head, typename... Tail>34void 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 45template <typename... Ts>46std::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} // namespace53 54BENCHMARK_EXPORT55std::string BenchmarkName::str() const {56 return join('/', function_name, args, min_time, min_warmup_time, iterations,57 repetitions, time_type, threads);58}59} // namespace benchmark60