native 0.0.1
Vectors, masks and wide register packs for C++26
Loading...
Searching...
No Matches
native.types.ccm
1// SPDX-FileCopyrightText: 2024 Edward Kmett <ekmett@gmail.com>
2// SPDX-License-Identifier: BSD-2-Clause OR Apache-2.0
3module;
4#include <cstdlib>
5#include <memory>
6#include <string>
7#include <string_view>
8#include <type_traits>
9#include <typeinfo>
10#if !defined(_MSC_VER) && __has_include(<cxxabi.h>)
11#include <cxxabi.h>
12#endif
13#include "native/attributes.h"
14#include "native/mask_traits.h"
15
16export module native.types;
17
19
24export namespace native {
26using ::native::mask_traits;
28using ::native::mask;
31
39template <typename T>
40inline std::string_view const type = [] native_nodiscard static -> std::string_view {
41 // nb: copying into string is necessary because the demangled name is ephemeral
42 static std::string const body = [] native_nodiscard static -> std::string {
43 #if !defined(_MSC_VER) && __has_include(<cxxabi.h>)
44 int status = 0;
45 std::unique_ptr<char, decltype(&std::free)> demangled(
46 abi::__cxa_demangle(typeid(T).name(), nullptr, nullptr, &status),
47 &std::free
48 );
49 if (status != 0 || !demangled) {
50 return typeid(T).name();
51 }
52 return demangled.get();
53 #else
54 // MSVC ABI has no __cxa_demangle; the string still owns the returned name.
55 return typeid(T).name();
56 #endif
57 }();
58 return body;
59}();
60
65std::string_view type_of(auto const & t) {
66 return type<std::remove_cvref_t<decltype(t)>>;
67}
68
70template <typename T, typename ... candidates>
71concept one_of_t = (std::is_same_v<T,candidates> || ... || false);
72
74template <typename T, typename ... candidates>
75concept not_one_of_t = (!one_of_t<T,candidates...>);
77}
Compiler attributes for host code, with shader-safe shared modifiers.
type T is not one of the candidates
type T is one of the candidates
#define native_nodiscard
C++17 [[nodiscard]].
Definition attributes.h:189
std::string_view const type
typename mask_traits< std::remove_cvref_t< T > >::type mask
Definition mask_traits.h:22
std::string_view type_of(auto const &t)
Architecture-tagged vectors, register packs and supporting value types. Native arithmetic follows its...