File indexing completed on 2024-05-12 04:39:13

0001 /*
0002     SPDX-FileCopyrightText: 2013 Olivier de Gaalon <olivier.jg@gmail.com>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #ifndef TEMPLATEHELPERS_H
0008 #define TEMPLATEHELPERS_H
0009 
0010 #include <QDebug>
0011 
0012 #include <type_traits>
0013 
0014 enum class Decision
0015 {
0016     True,
0017     False,
0018     Maybe
0019 };
0020 
0021 // see also: http://flamingdangerzone.com/cxx11/2012/06/01/almost-static-if.html
0022 namespace detail { enum class enabler {}; }
0023 constexpr detail::enabler dummy = {};
0024 template <bool Condition>
0025 using EnableIf = typename std::enable_if<Condition, detail::enabler>::type;
0026 
0027 inline QDebug operator<<(QDebug dbg, Decision decision)
0028 {
0029     switch (decision) {
0030     case Decision::True:  dbg << "true"; break;
0031     case Decision::False: dbg << "false"; break;
0032     default:              dbg << "maybe"; break;
0033     }
0034     return dbg;
0035 }
0036 
0037 #endif //TEMPLATEHELPERS_H