-
Notifications
You must be signed in to change notification settings - Fork 1
/
literals.cpp
58 lines (47 loc) · 1.28 KB
/
literals.cpp
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
// {"category": "C++11", "notes": "User defined literals"}
#include <SDKDDKVer.h>
#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <algorithm>
#include <Windows.h>
using namespace std;
//------------------------------------------------------------------------------
//
// User defined literals
//
//------------------------------------------------------------------------------
constexpr long double operator "" _percent(long double percent)
{
return percent / 100.0;
}
string operator "" _lodash(_In_ const char* cstring, size_t)
{
string s(cstring);
for_each(s.begin(), s.end(), [](char& c)
{
if (isspace(c))
{
c = '_';
}
else
{
c = tolower(c);
}
});
return s;
}
//------------------------------------------------------------------------------
//
// Demo execution
//
//------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
constexpr auto c_size = static_cast<size_t>(MAXINT16 * 25.0_percent);
string underscoreDelimitedLowerCaseString =
"The Quick Brown FOX Jumps Over a Lazy Dog"_lodash;
cout << c_size << endl;
cout << underscoreDelimitedLowerCaseString.c_str() << endl;
return 0;
}