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`

What's the name of the logical fallacy where a debater extends a statement far beyond the original statement to make it true?

Why should universal income be universal?

Why is it that I can sometimes guess the next note?

Do we have to expect a queue for the shuttle from Watford Junction to Harry Potter Studio?

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

Is it necessary to use pronouns with the verb "essere"?

The Digit Triangles

Is this part of the description of the Archfey warlock's Misty Escape feature redundant?

What does Apple's new App Store requirement mean

How much theory knowledge is actually used while playing?

How do I tell my boss that I'm quitting soon, especially given that a colleague just left this week

Is it allowed to activate the ability of multiple planeswalkers in a single turn?

Does the reader need to like the PoV character?

Creating two special characters

Shouldn’t conservatives embrace universal basic income?

Doesn't the system of the Supreme Court oppose justice?

Permission on Database

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?

Pre-mixing cryogenic fuels and using only one fuel tank

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

Why does Carol not get rid of the Kree symbol on her suit when she changes its colours?

Why Shazam when there is already Superman?

What to do when eye contact makes your coworker uncomfortable?

What is the English pronunciation of "pain au chocolat"?



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
    6 hours ago











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

    – Aart Stuurman
    6 hours ago






  • 4





    Maybe you can do something with std::is_constant_evaluated?

    – 0x5453
    6 hours ago











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

    – Jesper Juhl
    6 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
    5 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
    6 hours ago











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

    – Aart Stuurman
    6 hours ago






  • 4





    Maybe you can do something with std::is_constant_evaluated?

    – 0x5453
    6 hours ago











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

    – Jesper Juhl
    6 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
    5 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 5 hours ago









max66

38.1k74471




38.1k74471










asked 6 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
    6 hours ago











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

    – Aart Stuurman
    6 hours ago






  • 4





    Maybe you can do something with std::is_constant_evaluated?

    – 0x5453
    6 hours ago











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

    – Jesper Juhl
    6 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
    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
    6 hours ago











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

    – Aart Stuurman
    6 hours ago






  • 4





    Maybe you can do something with std::is_constant_evaluated?

    – 0x5453
    6 hours ago











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

    – Jesper Juhl
    6 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
    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
6 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
6 hours ago













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

– Aart Stuurman
6 hours ago





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

– Aart Stuurman
6 hours ago




4




4





Maybe you can do something with std::is_constant_evaluated?

– 0x5453
6 hours ago





Maybe you can do something with std::is_constant_evaluated?

– 0x5453
6 hours ago













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

– Jesper Juhl
6 hours ago





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

– Jesper Juhl
6 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
5 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
5 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
    5 hours ago











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

    – max66
    5 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
      5 hours ago











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

      – max66
      5 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
      5 hours ago











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

      – max66
      5 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 5 hours ago

























    answered 5 hours ago









    max66max66

    38.1k74471




    38.1k74471












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

      – matovitch
      5 hours ago











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

      – max66
      5 hours ago

















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

      – matovitch
      5 hours ago











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

      – max66
      5 hours ago
















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

    – matovitch
    5 hours ago





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

    – matovitch
    5 hours ago













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

    – max66
    5 hours ago





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

    – max66
    5 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 2 hours ago

























    answered 3 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 4 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

            How to create a command for the “strange m” symbol in latex? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)How do you make your own symbol when Detexify fails?Writing bold small caps with mathpazo packageplus-minus symbol with parenthesis around the minus signGreek character in Beamer document titleHow to create dashed right arrow over symbol?Currency symbol: Turkish LiraDouble prec as a single symbol?Plus Sign Too Big; How to Call adfbullet?Is there a TeX macro for three-legged pi?How do I get my integral-like symbol to align like the integral?How to selectively substitute a letter with another symbol representing the same letterHow do I generate a less than symbol and vertical bar that are the same height?

            Българска екзархия Съдържание История | Български екзарси | Вижте също | Външни препратки | Литература | Бележки | НавигацияУстав за управлението на българската екзархия. Цариград, 1870Слово на Ловешкия митрополит Иларион при откриването на Българския народен събор в Цариград на 23. II. 1870 г.Българската правда и гръцката кривда. От С. М. (= Софийски Мелетий). Цариград, 1872Предстоятели на Българската екзархияПодмененият ВеликденИнформационна агенция „Фокус“Димитър Ризов. Българите в техните исторически, етнографически и политически граници (Атлас съдържащ 40 карти). Berlin, Königliche Hoflithographie, Hof-Buch- und -Steindruckerei Wilhelm Greve, 1917Report of the International Commission to Inquire into the Causes and Conduct of the Balkan Wars

            Чепеларе Съдържание География | История | Население | Спортни и природни забележителности | Културни и исторически обекти | Религии | Обществени институции | Известни личности | Редовни събития | Галерия | Източници | Литература | Външни препратки | Навигация41°43′23.99″ с. ш. 24°41′09.99″ и. д. / 41.723333° с. ш. 24.686111° и. д.*ЧепелареЧепеларски Linux fest 2002Начало на Зимен сезон 2005/06Национални хайдушки празници „Капитан Петко Войвода“Град ЧепелареЧепеларе – народният ски курортbgrod.orgwww.terranatura.hit.bgСправка за населението на гр. Исперих, общ. Исперих, обл. РазградМузей на родопския карстМузей на спорта и скитеЧепеларебългарскибългарскианглийскитукИстория на градаСки писти в ЧепелареВремето в ЧепелареРадио и телевизия в ЧепелареЧепеларе мами с родопски чар и добри пистиЕвтин туризъм и снежни атракции в ЧепелареМестоположениеИнформация и снимки от музея на родопския карст3D панорами от ЧепелареЧепелареррр