The Gaudi Framework  master (b9786168)
Loading...
Searching...
No Matches
detected.h
Go to the documentation of this file.
1/***********************************************************************************\
2* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3* *
4* This software is distributed under the terms of the Apache version 2 licence, *
5* copied verbatim in the file "LICENSE". *
6* *
7* In applying this licence, CERN does not waive the privileges and immunities *
8* granted to it by virtue of its status as an Intergovernmental Organization *
9* or submit itself to any jurisdiction. *
10\***********************************************************************************/
11#pragma once
12// implementation of Library Fundamentals TS V2 detected idiom,
13// taken from http://en.cppreference.com/w/cpp/experimental/is_detected
14// and http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4436.pdf
15
16#include <type_traits>
17
18namespace Gaudi::cpp17 {
19 namespace details {
20
22 template <typename Default, typename AlwaysVoid, template <typename...> class Op, typename... Args>
23 struct detector {
24 constexpr static bool value = false;
25 using type = Default;
26 using value_t = std::false_type;
27 };
28
30 template <typename Default, template <typename...> class Op, typename... Args>
31 struct detector<Default, std::void_t<Op<Args...>>, Op, Args...> {
32 constexpr static bool value = true;
33 using type = Op<Args...>;
34 using value_t = std::true_type;
35 };
36 } // namespace details
37
38 template <template <class...> class Op, class... Args>
39 using is_detected = details::detector<void, void, Op, Args...>;
40
41 template <template <class...> class Op, class... Args>
42 inline constexpr bool is_detected_v = is_detected<Op, Args...>::value;
43
44 template <template <class...> class Op, class... Args>
45 using detected_t = typename is_detected<Op, Args...>::type;
46
47 // Op<Args...> if that is a valid type, otherwise Default.
48 template <typename Default, template <typename...> class Op, typename... Args>
49 using detected_or_t = typename details::detector<Default, void, Op, Args...>::type;
50
51} // namespace Gaudi::cpp17
details::detector< void, void, Op, Args... > is_detected
Definition detected.h:39
constexpr bool is_detected_v
Definition detected.h:42
typename details::detector< Default, void, Op, Args... >::type detected_or_t
Definition detected.h:49
typename is_detected< Op, Args... >::type detected_t
Definition detected.h:45
STL namespace.
Implementation of the detection idiom (negative case).
Definition detected.h:23