C++ check if statement can be evaluated constexprWhat are the differences between a pointer variable and a reference variable in C++?Is it possible to write a template to check for a function's existence?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhy can templates only be implemented in the header file?What is the effect of extern “C” in C++?What is the “-->” operator in C++?Easiest way to convert int to string in C++Why is reading lines from stdin much slower in C++ than Python?Difference between `constexpr` and `const`

C++ copy constructor called at return

Is there a RAID 0 Equivalent for RAM?

How does electrical safety system work on ISS?

What does Apple's new App Store requirement mean

Can I cause damage to electrical appliances by unplugging them when they are turned on?

I found an audio circuit and I built it just fine, but I find it a bit too quiet. How do I amplify the output so that it is a bit louder?

15% tax on $7.5k earnings. Is that right?

When were female captains banned from Starfleet?

Can you use Vicious Mockery to win an argument or gain favours?

Will number of steps recorded on FitBit/any fitness tracker add up distance in PokemonGo?

A Trivial Diagnosis

Which Article Helped Get Rid of Technobabble in RPGs?

Taxes on Dividends in a Roth IRA

Has the laser at Magurele, Romania reached a tenth of the Sun's power?

Are cause and effect the same as in our Universe in a non-relativistic, Newtonian Universe in which the speed of light is infinite?

Creating two special characters

What does "Scientists rise up against statistical significance" mean? (Comment in Nature)

Circuit Analysis: Obtaining Close Loop OP - AMP Transfer function

How would you translate "more" for use as an interface button?

PTIJ: Why is Haman obsessed with Bose?

Review your own paper in Mathematics

What kind of floor tile is this?

Is this toilet slogan correct usage of the English language?

Can I say "fingers" when referring to toes?



C++ check if statement can be evaluated constexpr


What are the differences between a pointer variable and a reference variable in C++?Is it possible to write a template to check for a function's existence?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListWhy can templates only be implemented in the header file?What is the effect of extern “C” in C++?What is the “-->” operator in C++?Easiest way to convert int to string in C++Why is reading lines from stdin much slower in C++ than Python?Difference between `constexpr` and `const`













8















Is there a method to decide whether something can be constexpr evaluated, and use the result as a constexpr boolean? My simplified use case is as follows:



template <typename base>
class derived

template<size_t size>
void do_stuff() (...)

void do_stuff(size_t size) (...)
public:
void execute()

if constexpr(is_constexpr(base::get_data())

do_stuff<base::get_data()>();

else

do_stuff(base::get_data());





My target is C++2a.



I found the following reddit thread, but I'm not a big fan of the macros. https://www.reddit.com/r/cpp/comments/7c208c/is_constexpr_a_macro_that_check_if_an_expression/










share|improve this question
























  • Hmm, the body of a if constexpr will only be evaluated if the expression in the if constexpr is true at compile time. Is that what you are looking for?

    – Jesper Juhl
    5 hours ago











  • But what if the test in the if constexpr([test]) is not evaluatable at compile time?

    – Aart Stuurman
    5 hours ago






  • 3





    Maybe you can do something with std::is_constant_evaluated?

    – 0x5453
    5 hours ago











  • en.cppreference.com/w/cpp/language/if

    – Jesper Juhl
    5 hours ago






  • 1





    @AartStuurman: What is do_stuff that it can run at compile time or runtime, but itself should not be constexpr? Wouldn't it make more sense to just make it a constexpr function, and pass it the value of get_data as a parameter?

    – Nicol Bolas
    4 hours ago















8















Is there a method to decide whether something can be constexpr evaluated, and use the result as a constexpr boolean? My simplified use case is as follows:



template <typename base>
class derived

template<size_t size>
void do_stuff() (...)

void do_stuff(size_t size) (...)
public:
void execute()

if constexpr(is_constexpr(base::get_data())

do_stuff<base::get_data()>();

else

do_stuff(base::get_data());





My target is C++2a.



I found the following reddit thread, but I'm not a big fan of the macros. https://www.reddit.com/r/cpp/comments/7c208c/is_constexpr_a_macro_that_check_if_an_expression/










share|improve this question
























  • Hmm, the body of a if constexpr will only be evaluated if the expression in the if constexpr is true at compile time. Is that what you are looking for?

    – Jesper Juhl
    5 hours ago











  • But what if the test in the if constexpr([test]) is not evaluatable at compile time?

    – Aart Stuurman
    5 hours ago






  • 3





    Maybe you can do something with std::is_constant_evaluated?

    – 0x5453
    5 hours ago











  • en.cppreference.com/w/cpp/language/if

    – Jesper Juhl
    5 hours ago






  • 1





    @AartStuurman: What is do_stuff that it can run at compile time or runtime, but itself should not be constexpr? Wouldn't it make more sense to just make it a constexpr function, and pass it the value of get_data as a parameter?

    – Nicol Bolas
    4 hours ago













8












8








8


4






Is there a method to decide whether something can be constexpr evaluated, and use the result as a constexpr boolean? My simplified use case is as follows:



template <typename base>
class derived

template<size_t size>
void do_stuff() (...)

void do_stuff(size_t size) (...)
public:
void execute()

if constexpr(is_constexpr(base::get_data())

do_stuff<base::get_data()>();

else

do_stuff(base::get_data());





My target is C++2a.



I found the following reddit thread, but I'm not a big fan of the macros. https://www.reddit.com/r/cpp/comments/7c208c/is_constexpr_a_macro_that_check_if_an_expression/










share|improve this question
















Is there a method to decide whether something can be constexpr evaluated, and use the result as a constexpr boolean? My simplified use case is as follows:



template <typename base>
class derived

template<size_t size>
void do_stuff() (...)

void do_stuff(size_t size) (...)
public:
void execute()

if constexpr(is_constexpr(base::get_data())

do_stuff<base::get_data()>();

else

do_stuff(base::get_data());





My target is C++2a.



I found the following reddit thread, but I'm not a big fan of the macros. https://www.reddit.com/r/cpp/comments/7c208c/is_constexpr_a_macro_that_check_if_an_expression/







c++ templates template-meta-programming constexpr c++20






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 4 hours ago









max66

38.1k74471




38.1k74471










asked 5 hours ago









Aart StuurmanAart Stuurman

920726




920726












  • Hmm, the body of a if constexpr will only be evaluated if the expression in the if constexpr is true at compile time. Is that what you are looking for?

    – Jesper Juhl
    5 hours ago











  • But what if the test in the if constexpr([test]) is not evaluatable at compile time?

    – Aart Stuurman
    5 hours ago






  • 3





    Maybe you can do something with std::is_constant_evaluated?

    – 0x5453
    5 hours ago











  • en.cppreference.com/w/cpp/language/if

    – Jesper Juhl
    5 hours ago






  • 1





    @AartStuurman: What is do_stuff that it can run at compile time or runtime, but itself should not be constexpr? Wouldn't it make more sense to just make it a constexpr function, and pass it the value of get_data as a parameter?

    – Nicol Bolas
    4 hours ago

















  • Hmm, the body of a if constexpr will only be evaluated if the expression in the if constexpr is true at compile time. Is that what you are looking for?

    – Jesper Juhl
    5 hours ago











  • But what if the test in the if constexpr([test]) is not evaluatable at compile time?

    – Aart Stuurman
    5 hours ago






  • 3





    Maybe you can do something with std::is_constant_evaluated?

    – 0x5453
    5 hours ago











  • en.cppreference.com/w/cpp/language/if

    – Jesper Juhl
    5 hours ago






  • 1





    @AartStuurman: What is do_stuff that it can run at compile time or runtime, but itself should not be constexpr? Wouldn't it make more sense to just make it a constexpr function, and pass it the value of get_data as a parameter?

    – Nicol Bolas
    4 hours ago
















Hmm, the body of a if constexpr will only be evaluated if the expression in the if constexpr is true at compile time. Is that what you are looking for?

– Jesper Juhl
5 hours ago





Hmm, the body of a if constexpr will only be evaluated if the expression in the if constexpr is true at compile time. Is that what you are looking for?

– Jesper Juhl
5 hours ago













But what if the test in the if constexpr([test]) is not evaluatable at compile time?

– Aart Stuurman
5 hours ago





But what if the test in the if constexpr([test]) is not evaluatable at compile time?

– Aart Stuurman
5 hours ago




3




3





Maybe you can do something with std::is_constant_evaluated?

– 0x5453
5 hours ago





Maybe you can do something with std::is_constant_evaluated?

– 0x5453
5 hours ago













en.cppreference.com/w/cpp/language/if

– Jesper Juhl
5 hours ago





en.cppreference.com/w/cpp/language/if

– Jesper Juhl
5 hours ago




1




1





@AartStuurman: What is do_stuff that it can run at compile time or runtime, but itself should not be constexpr? Wouldn't it make more sense to just make it a constexpr function, and pass it the value of get_data as a parameter?

– Nicol Bolas
4 hours ago





@AartStuurman: What is do_stuff that it can run at compile time or runtime, but itself should not be constexpr? Wouldn't it make more sense to just make it a constexpr function, and pass it the value of get_data as a parameter?

– Nicol Bolas
4 hours ago












3 Answers
3






active

oldest

votes


















5














Not exactly what you asked (I've developer a custom type trait specific for a get_value() static method... maybe it's possible to generalize it but, at the moment, I don't know how) but I suppose you can use SFINAE and make something as follows



#include <iostream>
#include <type_traits>

template <typename T>
constexpr auto icee_helper (int)
-> decltype( std::integral_constant<decltype(T::get_data()), T::get_data()>,
std::true_type );

template <typename>
constexpr auto icee_helper (long)
-> std::false_type;

template <typename T>
using isConstExprEval = decltype(icee_helper<T>(0));

template <typename base>
struct derived

template <std::size_t I>
void do_stuff()
std::cout << "constexpr case (" << I << ')' << std::endl;

void do_stuff (std::size_t i)
std::cout << "not constexpr case (" << i << ')' << std::endl;

void execute ()

if constexpr ( isConstExprEval<base>::value )
do_stuff<base::get_data()>();
else
do_stuff(base::get_data());

;

struct foo
static constexpr std::size_t get_data () return 1u; ;

struct bar
static std::size_t get_data () return 2u; ;

int main ()

derived<foo>.execute(); // print "constexpr case (1)"
derived<bar>.execute(); // print "not constexpr case (2)"






share|improve this answer

























  • This is madness, this use of the comma operator, the long/int overload... Have an upvote. :/

    – matovitch
    4 hours ago











  • @matovitch - never underestimate the power of the comma operator }:‑)

    – max66
    4 hours ago


















4














Here's another solution, which is more generic (applicable to any expression, without defining a separate template each time).



This solution leverages that (1) lambda expressions can be constexpr as of C++17 (2) the type of a captureless lambda is default constructible as of C++20.



The idea is, the overload that returns true is selected when and only when Lambda() can appear within a template argument, which effectively requires the lambda invocation to be a constant expression.



template<class Lambda, int=(Lambda(), 0)>
constexpr bool is_constexpr(Lambda) return true;
constexpr bool is_constexpr(...) return false;

template <typename base>
class derived

// ...

void execute()

if constexpr(is_constexpr([] base::get_data(); ))
do_stuff<base::get_data()>();
else
do_stuff(base::get_data());







share|improve this answer

























  • Intriguing solution... this way you get the same result of my custom type traits but more synthetically and, above all, the exact expression verified (base::get_data()) is embedded in the argument and not hard-coded as in my solution. Very nice. I have to remember it.

    – max66
    1 hour ago



















2














template<auto> struct require_constant;
template<class T>
concept has_constexpr_data = requires typename require_constant<T::get_data()>; ;


This is basically what's used by std::ranges::split_view.






share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288555%2fc-check-if-statement-can-be-evaluated-constexpr%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    Not exactly what you asked (I've developer a custom type trait specific for a get_value() static method... maybe it's possible to generalize it but, at the moment, I don't know how) but I suppose you can use SFINAE and make something as follows



    #include <iostream>
    #include <type_traits>

    template <typename T>
    constexpr auto icee_helper (int)
    -> decltype( std::integral_constant<decltype(T::get_data()), T::get_data()>,
    std::true_type );

    template <typename>
    constexpr auto icee_helper (long)
    -> std::false_type;

    template <typename T>
    using isConstExprEval = decltype(icee_helper<T>(0));

    template <typename base>
    struct derived

    template <std::size_t I>
    void do_stuff()
    std::cout << "constexpr case (" << I << ')' << std::endl;

    void do_stuff (std::size_t i)
    std::cout << "not constexpr case (" << i << ')' << std::endl;

    void execute ()

    if constexpr ( isConstExprEval<base>::value )
    do_stuff<base::get_data()>();
    else
    do_stuff(base::get_data());

    ;

    struct foo
    static constexpr std::size_t get_data () return 1u; ;

    struct bar
    static std::size_t get_data () return 2u; ;

    int main ()

    derived<foo>.execute(); // print "constexpr case (1)"
    derived<bar>.execute(); // print "not constexpr case (2)"






    share|improve this answer

























    • This is madness, this use of the comma operator, the long/int overload... Have an upvote. :/

      – matovitch
      4 hours ago











    • @matovitch - never underestimate the power of the comma operator }:‑)

      – max66
      4 hours ago















    5














    Not exactly what you asked (I've developer a custom type trait specific for a get_value() static method... maybe it's possible to generalize it but, at the moment, I don't know how) but I suppose you can use SFINAE and make something as follows



    #include <iostream>
    #include <type_traits>

    template <typename T>
    constexpr auto icee_helper (int)
    -> decltype( std::integral_constant<decltype(T::get_data()), T::get_data()>,
    std::true_type );

    template <typename>
    constexpr auto icee_helper (long)
    -> std::false_type;

    template <typename T>
    using isConstExprEval = decltype(icee_helper<T>(0));

    template <typename base>
    struct derived

    template <std::size_t I>
    void do_stuff()
    std::cout << "constexpr case (" << I << ')' << std::endl;

    void do_stuff (std::size_t i)
    std::cout << "not constexpr case (" << i << ')' << std::endl;

    void execute ()

    if constexpr ( isConstExprEval<base>::value )
    do_stuff<base::get_data()>();
    else
    do_stuff(base::get_data());

    ;

    struct foo
    static constexpr std::size_t get_data () return 1u; ;

    struct bar
    static std::size_t get_data () return 2u; ;

    int main ()

    derived<foo>.execute(); // print "constexpr case (1)"
    derived<bar>.execute(); // print "not constexpr case (2)"






    share|improve this answer

























    • This is madness, this use of the comma operator, the long/int overload... Have an upvote. :/

      – matovitch
      4 hours ago











    • @matovitch - never underestimate the power of the comma operator }:‑)

      – max66
      4 hours ago













    5












    5








    5







    Not exactly what you asked (I've developer a custom type trait specific for a get_value() static method... maybe it's possible to generalize it but, at the moment, I don't know how) but I suppose you can use SFINAE and make something as follows



    #include <iostream>
    #include <type_traits>

    template <typename T>
    constexpr auto icee_helper (int)
    -> decltype( std::integral_constant<decltype(T::get_data()), T::get_data()>,
    std::true_type );

    template <typename>
    constexpr auto icee_helper (long)
    -> std::false_type;

    template <typename T>
    using isConstExprEval = decltype(icee_helper<T>(0));

    template <typename base>
    struct derived

    template <std::size_t I>
    void do_stuff()
    std::cout << "constexpr case (" << I << ')' << std::endl;

    void do_stuff (std::size_t i)
    std::cout << "not constexpr case (" << i << ')' << std::endl;

    void execute ()

    if constexpr ( isConstExprEval<base>::value )
    do_stuff<base::get_data()>();
    else
    do_stuff(base::get_data());

    ;

    struct foo
    static constexpr std::size_t get_data () return 1u; ;

    struct bar
    static std::size_t get_data () return 2u; ;

    int main ()

    derived<foo>.execute(); // print "constexpr case (1)"
    derived<bar>.execute(); // print "not constexpr case (2)"






    share|improve this answer















    Not exactly what you asked (I've developer a custom type trait specific for a get_value() static method... maybe it's possible to generalize it but, at the moment, I don't know how) but I suppose you can use SFINAE and make something as follows



    #include <iostream>
    #include <type_traits>

    template <typename T>
    constexpr auto icee_helper (int)
    -> decltype( std::integral_constant<decltype(T::get_data()), T::get_data()>,
    std::true_type );

    template <typename>
    constexpr auto icee_helper (long)
    -> std::false_type;

    template <typename T>
    using isConstExprEval = decltype(icee_helper<T>(0));

    template <typename base>
    struct derived

    template <std::size_t I>
    void do_stuff()
    std::cout << "constexpr case (" << I << ')' << std::endl;

    void do_stuff (std::size_t i)
    std::cout << "not constexpr case (" << i << ')' << std::endl;

    void execute ()

    if constexpr ( isConstExprEval<base>::value )
    do_stuff<base::get_data()>();
    else
    do_stuff(base::get_data());

    ;

    struct foo
    static constexpr std::size_t get_data () return 1u; ;

    struct bar
    static std::size_t get_data () return 2u; ;

    int main ()

    derived<foo>.execute(); // print "constexpr case (1)"
    derived<bar>.execute(); // print "not constexpr case (2)"







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 4 hours ago

























    answered 4 hours ago









    max66max66

    38.1k74471




    38.1k74471












    • This is madness, this use of the comma operator, the long/int overload... Have an upvote. :/

      – matovitch
      4 hours ago











    • @matovitch - never underestimate the power of the comma operator }:‑)

      – max66
      4 hours ago

















    • This is madness, this use of the comma operator, the long/int overload... Have an upvote. :/

      – matovitch
      4 hours ago











    • @matovitch - never underestimate the power of the comma operator }:‑)

      – max66
      4 hours ago
















    This is madness, this use of the comma operator, the long/int overload... Have an upvote. :/

    – matovitch
    4 hours ago





    This is madness, this use of the comma operator, the long/int overload... Have an upvote. :/

    – matovitch
    4 hours ago













    @matovitch - never underestimate the power of the comma operator }:‑)

    – max66
    4 hours ago





    @matovitch - never underestimate the power of the comma operator }:‑)

    – max66
    4 hours ago













    4














    Here's another solution, which is more generic (applicable to any expression, without defining a separate template each time).



    This solution leverages that (1) lambda expressions can be constexpr as of C++17 (2) the type of a captureless lambda is default constructible as of C++20.



    The idea is, the overload that returns true is selected when and only when Lambda() can appear within a template argument, which effectively requires the lambda invocation to be a constant expression.



    template<class Lambda, int=(Lambda(), 0)>
    constexpr bool is_constexpr(Lambda) return true;
    constexpr bool is_constexpr(...) return false;

    template <typename base>
    class derived

    // ...

    void execute()

    if constexpr(is_constexpr([] base::get_data(); ))
    do_stuff<base::get_data()>();
    else
    do_stuff(base::get_data());







    share|improve this answer

























    • Intriguing solution... this way you get the same result of my custom type traits but more synthetically and, above all, the exact expression verified (base::get_data()) is embedded in the argument and not hard-coded as in my solution. Very nice. I have to remember it.

      – max66
      1 hour ago
















    4














    Here's another solution, which is more generic (applicable to any expression, without defining a separate template each time).



    This solution leverages that (1) lambda expressions can be constexpr as of C++17 (2) the type of a captureless lambda is default constructible as of C++20.



    The idea is, the overload that returns true is selected when and only when Lambda() can appear within a template argument, which effectively requires the lambda invocation to be a constant expression.



    template<class Lambda, int=(Lambda(), 0)>
    constexpr bool is_constexpr(Lambda) return true;
    constexpr bool is_constexpr(...) return false;

    template <typename base>
    class derived

    // ...

    void execute()

    if constexpr(is_constexpr([] base::get_data(); ))
    do_stuff<base::get_data()>();
    else
    do_stuff(base::get_data());







    share|improve this answer

























    • Intriguing solution... this way you get the same result of my custom type traits but more synthetically and, above all, the exact expression verified (base::get_data()) is embedded in the argument and not hard-coded as in my solution. Very nice. I have to remember it.

      – max66
      1 hour ago














    4












    4








    4







    Here's another solution, which is more generic (applicable to any expression, without defining a separate template each time).



    This solution leverages that (1) lambda expressions can be constexpr as of C++17 (2) the type of a captureless lambda is default constructible as of C++20.



    The idea is, the overload that returns true is selected when and only when Lambda() can appear within a template argument, which effectively requires the lambda invocation to be a constant expression.



    template<class Lambda, int=(Lambda(), 0)>
    constexpr bool is_constexpr(Lambda) return true;
    constexpr bool is_constexpr(...) return false;

    template <typename base>
    class derived

    // ...

    void execute()

    if constexpr(is_constexpr([] base::get_data(); ))
    do_stuff<base::get_data()>();
    else
    do_stuff(base::get_data());







    share|improve this answer















    Here's another solution, which is more generic (applicable to any expression, without defining a separate template each time).



    This solution leverages that (1) lambda expressions can be constexpr as of C++17 (2) the type of a captureless lambda is default constructible as of C++20.



    The idea is, the overload that returns true is selected when and only when Lambda() can appear within a template argument, which effectively requires the lambda invocation to be a constant expression.



    template<class Lambda, int=(Lambda(), 0)>
    constexpr bool is_constexpr(Lambda) return true;
    constexpr bool is_constexpr(...) return false;

    template <typename base>
    class derived

    // ...

    void execute()

    if constexpr(is_constexpr([] base::get_data(); ))
    do_stuff<base::get_data()>();
    else
    do_stuff(base::get_data());








    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 1 hour ago

























    answered 2 hours ago









    cpplearnercpplearner

    5,39722341




    5,39722341












    • Intriguing solution... this way you get the same result of my custom type traits but more synthetically and, above all, the exact expression verified (base::get_data()) is embedded in the argument and not hard-coded as in my solution. Very nice. I have to remember it.

      – max66
      1 hour ago


















    • Intriguing solution... this way you get the same result of my custom type traits but more synthetically and, above all, the exact expression verified (base::get_data()) is embedded in the argument and not hard-coded as in my solution. Very nice. I have to remember it.

      – max66
      1 hour ago

















    Intriguing solution... this way you get the same result of my custom type traits but more synthetically and, above all, the exact expression verified (base::get_data()) is embedded in the argument and not hard-coded as in my solution. Very nice. I have to remember it.

    – max66
    1 hour ago






    Intriguing solution... this way you get the same result of my custom type traits but more synthetically and, above all, the exact expression verified (base::get_data()) is embedded in the argument and not hard-coded as in my solution. Very nice. I have to remember it.

    – max66
    1 hour ago












    2














    template<auto> struct require_constant;
    template<class T>
    concept has_constexpr_data = requires typename require_constant<T::get_data()>; ;


    This is basically what's used by std::ranges::split_view.






    share|improve this answer



























      2














      template<auto> struct require_constant;
      template<class T>
      concept has_constexpr_data = requires typename require_constant<T::get_data()>; ;


      This is basically what's used by std::ranges::split_view.






      share|improve this answer

























        2












        2








        2







        template<auto> struct require_constant;
        template<class T>
        concept has_constexpr_data = requires typename require_constant<T::get_data()>; ;


        This is basically what's used by std::ranges::split_view.






        share|improve this answer













        template<auto> struct require_constant;
        template<class T>
        concept has_constexpr_data = requires typename require_constant<T::get_data()>; ;


        This is basically what's used by std::ranges::split_view.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 3 hours ago









        cpplearnercpplearner

        5,39722341




        5,39722341



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55288555%2fc-check-if-statement-can-be-evaluated-constexpr%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Are there any AGPL-style licences that require source code modifications to be public? Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Force derivative works to be publicAre there any GPL like licenses for Apple App Store?Do you violate the GPL if you provide source code that cannot be compiled?GPL - is it distribution to use libraries in an appliance loaned to customers?Distributing App for free which uses GPL'ed codeModifications of server software under GPL, with web/CLI interfaceDoes using an AGPLv3-licensed library prevent me from dual-licensing my own source code?Can I publish only select code under GPLv3 from a private project?Is there published precedent regarding the scope of covered work that uses AGPL software?If MIT licensed code links to GPL licensed code what should be the license of the resulting binary program?If I use a public API endpoint that has its source code licensed under AGPL in my app, do I need to disclose my source?

            2013 GY136 Descoberta | Órbita | Referências Menu de navegação«List Of Centaurs and Scattered-Disk Objects»«List of Known Trans-Neptunian Objects»

            Mortes em março de 2019 Referências Menu de navegação«Zhores Alferov, Nobel de Física bielorrusso, morre aos 88 anos - Ciência»«Fallece Rafael Torija, o bispo emérito de Ciudad Real»«Peter Hurford dies at 88»«Keith Flint, vocalista do The Prodigy, morre aos 49 anos»«Luke Perry, ator de 'Barrados no baile' e 'Riverdale', morre aos 52 anos»«Former Rangers and Scotland captain Eric Caldow dies, aged 84»«Morreu, aos 61 anos, a antiga lenda do wrestling King Kong Bundy»«Fallece el actor y director teatral Abraham Stavans»«In Memoriam Guillaume Faye»«Sidney Sheinberg, a Force Behind Universal and Spielberg, Is Dead at 84»«Carmine Persico, Colombo Crime Family Boss, Is Dead at 85»«Dirigent Michael Gielen gestorben»«Ciclista tricampeã mundial e prata na Rio 2016 é encontrada morta em casa aos 23 anos»«Pagan Community Notes: Raven Grimassi dies, Indianapolis pop-up event cancelled, Circle Sanctuary announces new podcast, and more!»«Hal Blaine, Wrecking Crew Drummer, Dies at 90»«Morre Coutinho, que editou dupla lendária com Pelé no Santos»«Cantor Demétrius, ídolo da Jovem Guarda, morre em SP»«Ex-presidente do Vasco, Eurico Miranda morre no Rio de Janeiro»«Bronze no Mundial de basquete de 1971, Laís Elena morre aos 76 anos»«Diretor de Corridas da F1, Charlie Whiting morre aos 66 anos às vésperas do GP da Austrália»«Morreu o cardeal Danneels, da Bélgica»«Morreu o cartoonista Augusto Cid»«Morreu a atriz Maria Isabel de Lizandra, de "Vale Tudo" e novelas da Tupi»«WS Merwin, prize-winning poet of nature, dies at 91»«Atriz Márcia Real morre em São Paulo aos 88 anos»«Mauritanie: décès de l'ancien président Mohamed Mahmoud ould Louly»«Morreu Dick Dale, o rei da surf guitar e de "Pulp Fiction"»«Falleció Víctor Genes»«João Carlos Marinho, autor de 'O Gênio do Crime', morre em SP»«Legendary Horror Director and SFX Artist John Carl Buechler Dies at 66»«Morre em Salvador a religiosa Makota Valdina»«مرگ بازیکن‌ سابق نساجی بر اثر سقوط سنگ در مازندران»«Domingos Oliveira morre no Rio»«Morre Airton Ravagniani, ex-São Paulo, Fla, Vasco, Grêmio e Sport - Notícias»«Morre o escritor Flavio Moreira da Costa»«Larry Cohen, Writer-Director of 'It's Alive' and 'Hell Up in Harlem,' Dies at 77»«Scott Walker, experimental singer-songwriter, dead at 76»«Joseph Pilato, Day of the Dead Star and Horror Favorite, Dies at 70»«Sheffield United set to pay tribute to legendary goalkeeper Ted Burgin who has died at 91»«Morre Rafael Henzel, sobrevivente de acidente aéreo da Chapecoense»«Morre Valery Bykovsky, um dos primeiros cosmonautas da União Soviética»«Agnès Varda, cineasta da Nouvelle Vague, morre aos 90 anos»«Agnès Varda, cineasta francesa, morre aos 90 anos»«Tania Mallet, James Bond Actress and Helen Mirren's Cousin, Dies at 77»e