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: 5bb29ca5dea14081c95563c217e22b7c600966ce (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
57
#pragma once
#include "base.hpp"
#include "macros.hpp"

#include "../std/string.hpp"
#include "../std/sstream.hpp"


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

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

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

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

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

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

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