Welcome to mirror list, hosted at ThFree Co, Russian Federation.

string_format.hpp « base - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c864c5682823cd9b927a0a8a7f83d504d27774ab (plain)
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
#pragma once
#include "base/base.hpp"
#include "base/macros.hpp"

#include <sstream>
#include <string>

namespace strings
{
  template <typename T>
  std::string ToString(T const & t)
  {
    // May be we should use DebugPrint here. Not sure.

    std::ostringstream out;
    out << t;
    return out.str();
  }

  std::string const FormatImpl(std::string const & s, std::string arr[], size_t count);

  template <typename T1>
  std::string const Format(std::string const & s, T1 const & t1)
  {
    std::string arr[] = { ToString(t1) };
    return FormatImpl(s, arr, ARRAY_SIZE(arr));
  }

  template <typename T1, typename T2>
  std::string const Format(std::string const & s, T1 const & t1, T2 const & t2)
  {
    std::string arr[] = { ToString(t1), ToString(t2) };
    return FormatImpl(s, arr, ARRAY_SIZE(arr));
  }

  template <typename T1, typename T2, typename T3>
  std::string const Format(std::string const & s, T1 const & t1, T2 const & t2, T3 const & t3)
  {
    std::string arr[] = { ToString(t1), ToString(t2), ToString(t3) };
    return FormatImpl(s, arr, ARRAY_SIZE(arr));
  }

  template <typename T1, typename T2, typename T3, typename T4>
  std::string const Format(std::string const & s, T1 const & t1, T2 const & t2, T3 const & t3, T4 const & t4)
  {
    std::string arr[] = { ToString(t1), ToString(t2), ToString(t3), ToString(t4) };
    return FormatImpl(s, arr, ARRAY_SIZE(arr));
  }

  template <typename T1, typename T2, typename T3, typename T4, typename T5>
  std::string const Format(std::string const & s, T1 const & t1, T2 const & t2, T3 const & t3, T4 const & t4, T5 const & t5)
  {
    std::string arr[] = { ToString(t1), ToString(t2), ToString(t3), ToString(t4), ToString(t5) };
    return FormatImpl(s, arr, ARRAY_SIZE(arr));
  }
}