/*! * \file utl/meta/detect.h * \brief Template meta-programming void helpers * * Copyright (C) 2018 Christos Choutouridis * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as * published by the Free Software Foundation, either version 3 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program. If not, see . */ #ifndef __utl_meta_detect_h__ #define __utl_meta_detect_h__ #include #include /*! * \ingroup meta * \defgroup detect * Implementation of the detection idiom */ //! @{ namespace utl { //! detection idiom (negative case). template class _Op, typename... _Args> struct detector_ { using value_ = false_; using type = _Def; }; //! detection idiom (positive case). template class _Op, typename... _Args> struct detector_ <_Def, void_t<_Op<_Args...>>, _Op, _Args...> { using value_ = true_; using type = _Op<_Args...>; }; // Detect whether _Op<_Args...> is a valid type, use _Def if not. template class _Op, typename... _Args> using detected_or_ = detector_ <_Def, void, _Op, _Args...>; // template alias template class _Op, typename... _Args> using detected_or_t = typename detected_or_<_Def, _Op, _Args...>::type; } //! @} #endif /* __utl_meta_detect_h__ */