#ifndef _melder_templates_h_ #define _melder_templates_h_ /* melder_templates.h * * Copyright (C) 1992-2019,2022 Paul Boersma * * This code is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This code 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this work. If not, see . */ //#define Melder_ENABLE_IF_ISA(A,B) , class = typename std::enable_if::value>::type #define Melder_ENABLE_IF_ISA(A,B) , class = typename std::enable_if_t::value> //#define Melder_ENABLE_IF_ISA(A,B) , class = typename std::enable_if_v> template class MelderCallback { public: using FunctionType = Ret* (*) (T*, Args...); MelderCallback (FunctionType f = nullptr) : _f (f) { } template MelderCallback (Ret2* (*f) (T2*, Args...)) : _f (reinterpret_cast (f)) { static_assert (std::is_base_of :: value, "First argument of MelderCallback should have covariant type."); static_assert (std::is_base_of :: value, "Return type of MelderCallback should be covariant."); }; Ret* operator () (T* data, Args ... args) { return _f (data, std::forward(args)...); } explicit operator bool () const noexcept { return !! _f; } FunctionType get() { return _f; } private: FunctionType _f; }; template class MelderCallback { // specialization public: using FunctionType = void (*) (T*, Args...); MelderCallback (FunctionType f = nullptr) : _f (f) { } template MelderCallback (void (*f) (T2*, Args...)) : _f (reinterpret_cast (f)) { static_assert (std::is_base_of :: value, "First argument of MelderCallback should have covariant type."); }; void operator () (T* data, Args ... args) { _f (data, std::forward(args)...); } explicit operator bool () const noexcept { return !! _f; } FunctionType get() { return _f; } private: FunctionType _f; }; template class MelderCallback { // specialization public: using FunctionType = int (*) (T*, Args...); MelderCallback (FunctionType f = nullptr) : _f (f) { } template MelderCallback (int (*f) (T2*, Args...)) : _f (reinterpret_cast (f)) { static_assert (std::is_base_of :: value, "First argument of MelderCallback should have covariant type."); }; int operator () (T* data, Args ... args) { return _f (data, std::forward(args)...); } explicit operator bool () const noexcept { return !! _f; } FunctionType get() { return _f; } private: FunctionType _f; }; template class MelderCompareHook { public: typedef int (*FunctionType) (T*, T*); MelderCompareHook (FunctionType f = nullptr) : _f (f) { } template MelderCompareHook (int (*f) (T2*, T2*)) : _f (reinterpret_cast (f)) { }; int operator () (T* data1, T* data2) noexcept { return _f (data1, data2); } explicit operator bool () const noexcept { return !! _f; } FunctionType get() { return _f; } private: FunctionType _f; }; template T** MelderPointerToPointerCast (Y **thing) { return (T**) thing; } /* End of file melder_templates.h */ #endif