BioC++
core-0.7.0
The Modern C++ libraries for Bioinformatics.
Loading...
Searching...
No Matches
type_inspection.hpp
Go to the documentation of this file.
1
// -----------------------------------------------------------------------------------------------------
2
// Copyright (c) 2022 deCODE Genetics
3
// Copyright (c) 2006-2020, Knut Reinert & Freie Universität Berlin
4
// Copyright (c) 2016-2020, Knut Reinert & MPI für molekulare Genetik
5
// This file may be used, modified and/or redistributed under the terms of the 3-clause BSD-License
6
// shipped with this file and also available at: https://github.com/biocpp/biocpp-core/blob/main/LICENSE.md
7
// -----------------------------------------------------------------------------------------------------
8
14
#pragma once
15
16
#if defined(__GNUC__) || defined(__clang__)
17
# include <cxxabi.h>
18
#endif
// defined(__GNUC__) || defined(__clang__)
19
20
#include <
functional
>
21
#include <
memory
>
22
#include <
string
>
23
#include <
typeinfo
>
24
25
#include <
bio/core.hpp
>
26
27
namespace
bio::meta::detail
28
{
29
44
template
<
typename
type>
45
inline
std::string
const
type_name_as_string = []()
46
{
47
std::string
demangled_name{};
48
#if defined(__GNUC__) || defined(__clang__)
// clang and gcc only return a mangled name.
49
using
safe_ptr_t =
std::unique_ptr
<char,
std::function
<void(
char
*)>>;
50
51
int
status
{};
52
safe_ptr_t demangled_name_ptr{abi::__cxa_demangle(
typeid
(type).name(), 0, 0, &status),
53
[](
char
* name_ptr) {
free
(name_ptr); }};
54
demangled_name =
std::string
{
std::addressof
(*demangled_name_ptr)};
55
#else
// e.g. MSVC
56
demangled_name =
typeid
(type).name();
57
#endif
// defined(__GNUC__) || defined(__clang__)
58
59
if
constexpr
(std::is_const_v<std::remove_reference_t<type>>)
60
demangled_name +=
" const"
;
61
if
constexpr
(std::is_lvalue_reference_v<type>)
62
demangled_name +=
" &"
;
63
if
constexpr
(std::is_rvalue_reference_v<type>)
64
demangled_name +=
" &&"
;
65
66
return
demangled_name;
67
}();
68
69
}
// namespace bio::meta::detail
std::addressof
T addressof(T... args)
std::string
core.hpp
Provides platform and dependency checks.
std::free
T free(T... args)
std::function
functional
memory
std::experimental::filesystem::status
T status(T... args)
string
typeinfo
std::unique_ptr
bio
meta
detail
type_inspection.hpp
Generated on Thu Mar 30 2023 15:25:52 for BioC++ by
1.9.6