mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-12-01 13:09:41 -06:00
SFINAE-constrain the GncOption constructor templates.
So that one can't instantiate an invalid constructor. Unfortunately Swig doesn't understand SFINAE and will try to create the invalid constructors anyway but at least this generates a compile-time error when it tries to.
This commit is contained in:
parent
43f4bcb610
commit
a602f64b17
@ -33,7 +33,10 @@ extern "C"
|
||||
#include <qoflog.h>
|
||||
}
|
||||
|
||||
template <typename ValueType>
|
||||
template <typename ValueType,
|
||||
typename std::enable_if_t<!std::is_base_of_v<OptionClassifier,
|
||||
std::decay_t<ValueType>>,
|
||||
int>>
|
||||
GncOption::GncOption(const char* section, const char* name,
|
||||
const char* key, const char* doc_string,
|
||||
ValueType value, GncOptionUIType ui_type) :
|
||||
|
@ -37,6 +37,7 @@ extern "C"
|
||||
#include "gnc-option-ui.hpp"
|
||||
#include "gnc-option-date.hpp"
|
||||
|
||||
struct OptionClassifier;
|
||||
class GncOptionUIItem;
|
||||
using GncOptionUIItemPtr = std::unique_ptr<GncOptionUIItem>;
|
||||
struct QofInstance_s;
|
||||
@ -65,10 +66,16 @@ using GncOptionVariantPtr = std::unique_ptr<GncOptionVariant>;
|
||||
class GncOption
|
||||
{
|
||||
public:
|
||||
template <typename OptionType>
|
||||
template <typename OptionType,
|
||||
typename std::enable_if_t<std::is_base_of_v<OptionClassifier,
|
||||
std::decay_t<OptionType>>,
|
||||
int> = 0>
|
||||
GncOption(OptionType option) :
|
||||
m_option{std::make_unique<GncOptionVariant>(option)} {}
|
||||
template <typename ValueType>
|
||||
template <typename ValueType,
|
||||
typename std::enable_if_t<!std::is_base_of_v<OptionClassifier,
|
||||
std::decay_t<ValueType>>,
|
||||
int> = 0>
|
||||
GncOption(const char* section, const char* name,
|
||||
const char* key, const char* doc_string,
|
||||
ValueType value,
|
||||
|
Loading…
Reference in New Issue
Block a user