MeVisLab Toolbox Reference
Loading...
Searching...
No Matches
mlTemplateHelpers.h
Go to the documentation of this file.
1/*************************************************************************************
2**
3** Copyright 2021, MeVis Medical Solutions AG
4**
5** The user may use this file in accordance with the license agreement provided with
6** the Software or, alternatively, in accordance with the terms contained in a
7** written agreement between the user and MeVis Medical Solutions AG.
8**
9** For further information use the contact form at https://www.mevislab.de/contact
10**
11**************************************************************************************/
12
13#pragma once
14
15#include "mlTypeDefs.h"
16
18
19/*
20 * Utility template for easier use within std::visit.
21 * See https://en.cppreference.com/w/cpp/utility/variant/visit
22 */
23template <class... Ts> struct Overload : Ts...
24{
25 using Ts::operator()...;
26};
27template <class... Ts> Overload(Ts...) -> Overload<Ts...>;
28
30//
31// The following implements the C++ standard 17 proposal N4502.
32// For further information see https://en.cppreference.com/w/cpp/experimental/is_detected
33//
35
36namespace internal
37{
38
39#if __GNUC__ < 5 && !defined __clang__
40 template <typename...> struct voider
41 {
42 using type = void;
43 };
44 template <typename... Ts> using void_t = typename voider<Ts...>::type;
45#else
46 template <typename...> using void_t = void;
47#endif
48
49 struct nonesuch
50 {
51 nonesuch() = delete;
52 ~nonesuch() = delete;
53 nonesuch(nonesuch const&) = delete;
54 void operator=(nonesuch const&) = delete;
55 };
56
57 // The primary template handles all types that do not support the archetypal Op.
58 template <class Default, class, template <class...> class Op, class... Args> struct detector
59 {
60 using value_t = std::false_type;
61 using type = Default;
62 };
63
64 // The specialization recognizes and handles only types supporting Op.
65 template <class Default, template <class...> class Op, class... Args>
66 struct detector<Default, void_t<Op<Args...>>, Op, Args...>
67 {
68 using value_t = std::true_type;
69 using type = Op<Args...>;
70 };
71} // namespace internal
72
73template <template <class...> class Op, class... Args> using is_detected =
74 typename internal::detector<internal::nonesuch, void, Op, Args...>::value_t;
75
76template <template <class...> class Op, class... Args> constexpr bool is_detected_v = is_detected<Op, Args...>::value;
77
78template <template <class...> class Op, class... Args> using detected_t =
79 typename internal::detector<internal::nonesuch, void, Op, Args...>::type;
80
81
Target mlrange_cast(Source arg)
Generic version of checked ML casts.
typename voider< Ts... >::type void_t
constexpr bool is_detected_v
typename internal::detector< internal::nonesuch, void, Op, Args... >::value_t is_detected
typename internal::detector< internal::nonesuch, void, Op, Args... >::type detected_t
void operator=(nonesuch const &)=delete
nonesuch(nonesuch const &)=delete