MCRO
C++23 utilities for Unreal Engine.
Loading...
Searching...
No Matches
TimespanLiterals.h
Go to the documentation of this file.
1/** @noop License Comment
2 * @file
3 * @copyright
4 * This Source Code is subject to the terms of the Mozilla Public License, v2.0.
5 * If a copy of the MPL was not distributed with this file You can obtain one at
6 * https://mozilla.org/MPL/2.0/
7 *
8 * @author David Mórász
9 * @date 2025
10 */
11
12#pragma once
13#include "CoreMinimal.h"
14#include "Mcro/Concepts.h"
15#include "Misc/Timespan.h"
16
18{
19 using namespace Mcro::Concepts;
20
21 namespace Detail
22 {
23 template <auto Function, char... ValueText>
24 constexpr FTimespan CreateFromParamPack()
25 {
26 static constexpr char string [sizeof...(ValueText) + 1] { ValueText..., '\0' };
27 double value = TCString<char>::Atod(string);
28 return Function(value);
29 }
30 }
31
32 template <char... Value>
33 constexpr FTimespan operator ""_Day ()
34 {
35 return Detail::CreateFromParamPack<&FTimespan::FromDays, Value...>();
36 }
37
38 template <char... Value>
39 constexpr FTimespan operator ""_Hour ()
40 {
41 return Detail::CreateFromParamPack<&FTimespan::FromHours, Value...>();
42 }
43
44 template <char... Value>
45 constexpr FTimespan operator ""_Min ()
46 {
47 return Detail::CreateFromParamPack<&FTimespan::FromMinutes, Value...>();
48 }
49
50 template <char... Value>
51 constexpr FTimespan operator ""_Sec ()
52 {
53 return Detail::CreateFromParamPack<&FTimespan::FromSeconds, Value...>();
54 }
55
56 template <char... Value>
57 constexpr FTimespan operator ""_mSec ()
58 {
59 return Detail::CreateFromParamPack<&FTimespan::FromMilliseconds, Value...>();
60 }
61
62 template <char... Value>
63 constexpr FTimespan operator ""_uSec ()
64 {
65 return Detail::CreateFromParamPack<&FTimespan::FromMicroseconds, Value...>();
66 }
67}
This header exists because STL headers in Android doesn't define STL concepts (other than same_as whi...
constexpr FTimespan CreateFromParamPack()