/
convert_to.h
47 lines (35 loc) · 1.37 KB
/
convert_to.h
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
// LAF Base Library
// Copyright (c) 2023 Igara Studio S.A.
// Copyright (c) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef BASE_CONVERT_TO_H_INCLUDED
#define BASE_CONVERT_TO_H_INCLUDED
#pragma once
#include "base/base.h"
#include "base/ints.h"
#include <string>
namespace base {
class Sha1;
class Uuid;
// Undefined convertion
template<typename To, typename From>
To convert_to(const From&) {
// We've to use the sizeof(To) trick to use static_assert(false)
// and make the compiler fail in non-specialized cases, see P2593R0:
// https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2593r0.html
static_assert(false && sizeof(To), "Invalid conversion"); // NOLINT readability-simplify-boolean-expr
}
template<> int convert_to(const std::string& from);
template<> std::string convert_to(const int& from);
template<> uint32_t convert_to(const std::string& from);
template<> std::string convert_to(const uint32_t& from);
template<> double convert_to(const std::string& from);
template<> std::string convert_to(const double& from);
template<> Sha1 convert_to(const std::string& from);
template<> std::string convert_to(const Sha1& from);
template<> Uuid convert_to(const std::string& from);
template<> std::string convert_to(const Uuid& from);
}
#endif