Skip to content
Snippets Groups Projects
Commit 95498200 authored by Walter Lampl's avatar Walter Lampl
Browse files

Merge branch 'memberRequires.CxxUtils-20210907' into 'master'

CxxUtils: Add ATH_MEMBER_REQUIRES.

See merge request !46357
parents 2f2843db 2e64b6a4
No related branches found
No related tags found
9 merge requests!69091Fix correlated smearing bug in JER in JetUncertainties in 22.0,!58791DataQualityConfigurations: Modify L1Calo config for web display,!51674Fixing hotSpotInHIST for Run3 HIST,!50012RecExConfig: Adjust log message levels from GetRunNumber and GetLBNumber,!46784MuonCondInterface: Enable thread-safety checking.,!46776Updated LArMonitoring config file for WD to match new files produced using MT,!46538Draft: Added missing xAOD::TrigConfKeys from DESDM_MCP,!46514TGC Digitization: Implementation of signal propagation time between the sensor edge and ASD,!46357CxxUtils: Add ATH_MEMBER_REQUIRES.
// This file's extension implies that it's C, but it's really -*- C++ -*-.
/*
* Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration.
* Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration.
*/
/**
* @file CxxUtils/concepts.h
......@@ -18,6 +18,21 @@
*
* The body of the ATH_REQUIRES will be hidden for compilers
* that don't support concepts.
*
* ATH_MEMBER_REQUIRES can be used to selectively enable a member function.
* Example:
*@code
* template <class T>
* class C { ...
*
* ATH_MEMBER_REQUIRES(std::is_same_v<T,int>, double) foo (double x) { ... }
@endcode
* declares a function @c foo returning @c double that is enabled
* only if @c T is an @c int. If you have a definition separate
* from the declaration, then use ATH_MEMBER_REQUIRES_DEF in the definition
* instead.
*
* Will use a @c requires clause with C++20 and @c enable_if otherwise.
*/
......@@ -25,15 +40,36 @@
#define CXXUTILS_CONCEPTS_H
#include <type_traits>
#ifdef __cpp_concepts
#include <concepts>
#define ATH_REQUIRES(...) requires __VA_ARGS__
#define ATH_MEMBER_REQUIRES(CONDITION, RETTYPE) \
template <bool = true> \
requires (CONDITION) \
RETTYPE
#define ATH_MEMBER_REQUIRES_DEF(CONDITION, RETTYPE) \
template <bool> \
requires (CONDITION) \
RETTYPE
#else
#define ATH_REQUIRES(...)
#define ATH_MEMBER_REQUIRES(CONDITION, RETTYPE) \
template <bool Enable = true> \
std::enable_if_t<Enable && (CONDITION), RETTYPE>
#define ATH_MEMBER_REQUIRES_DEF(CONDITION, RETTYPE) \
template <bool Enable> \
std::enable_if_t<Enable && (CONDITION), RETTYPE>
#endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment