forked from AndreyG/libgit2cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformat.h
More file actions
43 lines (36 loc) · 969 Bytes
/
Copy pathformat.h
File metadata and controls
43 lines (36 loc) · 969 Bytes
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
#pragma once
#include <cstdio>
#include <string>
#ifdef USE_BOOST
#include <boost/format.hpp>
#endif
namespace git {
namespace internal
{
#ifndef USE_BOOST
template<typename... Args>
inline std::string format(const char * fmt, Args&& ... args)
{
auto size = std::snprintf(nullptr, 0, fmt, args...);
std::string result(size, 0);
std::snprintf(&result[0], size + 1, fmt, args...);
return result;
}
#else
inline boost::format & format_apply(boost::format & fmt)
{
return fmt;
}
template<typename T, typename... Args>
boost::format & format_apply(boost::format & fmt, T && data, Args&& ... args)
{
return format_apply(fmt % data, std::forward<Args>(args)...);
}
template<typename... Args>
std::string format(const char * fmt_str, Args&& ... args)
{
boost::format fmt(fmt_str);
str(format_apply(fmt, std::forward<Args>(args)...));
}
#endif
}}