C++ Logo

STD-PROPOSALS

Advanced search

Subject: Re: [std-proposals] Feature test macro for variant<bool, string> taking const char* fix?
From: Barry Revzin (barry.revzin_at_[hidden])
Date: 2020-12-06 16:34:02


On Sun, Dec 6, 2020 at 4:29 PM Emile Cormier <emile.cormier.jr_at_[hidden]>
wrote:

> I do, Barry. Something like this (not tested):
>
> struct parse_event
> {
> template <typename T>
> parse_event(T&& value) : token(std::forward<T>(value)) {}
>
> #ifndef VARIANT_SAFELY_TAKES_CHAR_POINTER
> // Workaround
> parse_event(const char* s) : token(std::string(s)) {}
> #endif
>
> std::variant<bool, int, std::string> token;
> };
>
> The idea is to disable the workaround code when the C++ library
> implementation has the P0608/P1957 fixes.
>

You could just write:

struct parse_event
{
    template <typename T>
    parse_event(T&& value) : token(std::forward<T>(value)) {}

    // Workaround
    parse_event(const char* s) : token(std::string(s)) {}

    std::variant<bool, int, std::string> token;
};

This works regardless of whether the fix is implemented.

Barry



STD-PROPOSALS list run by std-proposals-owner@lists.isocpp.org

Standard Proposals Archives on Google Groups