-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcat.hpp
58 lines (49 loc) · 1.1 KB
/
concat.hpp
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
58
//
// Created by Rakesh on 29/03/2022.
//
#pragma once
#include <cstring>
#include <string>
namespace spt::util
{
namespace impl
{
inline std::size_t size( const char* s )
{
return std::strlen( s );
}
inline std::size_t size( const std::string& s )
{
return std::size( s );
}
inline std::size_t size( std::string_view s )
{
return std::size( s );
}
template <typename Head, typename... Tail>
std::size_t size( const Head& head, Tail const&... tail )
{
return size( head ) + size( tail... );
}
template <typename Head>
void append( std::string& out, const Head& head )
{
out.append( head );
}
template <typename Head, typename... Args>
void append( std::string& out, const Head& head, Args const&... args )
{
out.append( head );
append( out, args... );
}
}
template <typename... Args>
std::string concat( Args const&... args )
{
std::size_t total = impl::size( args... );
std::string out;
out.reserve( total );
impl::append( out, args... );
return out;
}
}