Adobe Source Libraries 1.49.0
A collection of C++ libraries.
Loading...
Searching...
No Matches
conversion.hpp
Go to the documentation of this file.
1/*
2 Copyright 2013 Adobe
3 Distributed under the Boost Software License, Version 1.0.
4 (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
5*/
6/**************************************************************************************************/
7
8#ifndef ADOBE_CONVERSION_HPP
9#define ADOBE_CONVERSION_HPP
10
11#include <adobe/config.hpp>
12#include <string>
13
14/**************************************************************************************************/
15
16namespace adobe {
17
18/**************************************************************************************************/
19
20template <class T>
21struct promote {
22 using type = std::
23 conditional_t<std::is_arithmetic_v<T> && (2 <= sizeof(T) && sizeof(T) <= 4), double, T>;
24};
25
26template <>
27struct promote<const char*> {
28 using type = std::string;
29};
30
31template <class T>
32using promote_t = typename promote<T>::type;
33
34/**************************************************************************************************/
35
36template <typename lht, typename rht>
37inline lht explicit_cast(const rht& rhs) {
38 return static_cast<lht>(rhs);
39}
40
41/**************************************************************************************************/
42
43template <typename R, typename T>
45 R operator()(T& x) const { return dynamic_cast<R>(x); }
46};
47
48template <typename R, typename T>
49inline R runtime_cast(T& x) {
50 return runtime_cast_t<R, T>()(x);
51}
52
53template <typename R, typename T>
54inline R runtime_cast(T* x) {
55 return runtime_cast_t<R, T*>()(x);
56}
57
58template <typename R, typename T>
59inline bool runtime_cast(const T& x, R& r) {
60 const R* p = runtime_cast<const R*>(&x);
61 if (!p)
62 return false;
63 r = *p;
64 return true;
65}
66
67/**************************************************************************************************/
68
69template <typename T>
70inline T& remove_const(const T& x) {
71 return const_cast<T&>(x);
72}
73
74/**************************************************************************************************/
75
76} // namespace adobe
77
78/**************************************************************************************************/
79
80#endif
81
82/**************************************************************************************************/
T & remove_const(const T &x)
lht explicit_cast(const rht &rhs)
typename promote< T >::type promote_t
R runtime_cast(T &x)
A struct for compile-time type promotion.
std::conditional_t< std::is_arithmetic_v< T > &&(2<=sizeof(T) &&sizeof(T)<=4), double, T > type
R operator()(T &x) const