Skip to content

Add support for using std::enable_if in value_traits specializations #21

@boris-kolpackov

Description

@boris-kolpackov

Motivating example:

template <typename EnumType>
class value_traits<EnumType, id_string, typename std::enable_if<std::is_enum<EnumType>::value>::type>
{
public:
    using query_type = EnumType;

    static void set_value(
            EnumType& value,
            details::buffer const& buffer,
            std::size_t n,
            bool isNull)
    {
        // deserialize database string to any enum value
    }

    static void set_image(
            details::buffer& buffer,
            std::size_t& n,
            bool& isNull,
            EnumType const& value)
    {
        // Serialize any enum value to database string
    }
};

To make this work would require changing the value_traits template from:

template <typename T, database_type_id ID>
class value_traits: public select_traits<T, ID>::type
{
};

To:

template <typename T, database_type_id ID, typename = void>
class value_traits: public select_traits<T, ID>::type
{
};

Which will break all the existing code that expects the old template.

So while the idea is good, we need to think how we can implement it without break backwards compatibility.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions