Nufunello / LRL

Less Routine Library - library provides with zero-cost abstraction solutions for trivial routine
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Optional expression #21

Open Nufunello opened 2 years ago

Nufunello commented 2 years ago

Motivation: provide API for selecting expressions at compile time at same code scope

if we want to execute different code depending on compile time expression we will use if constexpr, but when if there is need to use const if constexpr won't work

Nufunello commented 2 years ago

For example:

{
    auto res = 1;
    if constexpr (do_multiply)
    {
         res *= 2;
    }
    return res;
}

In this case, would be good thing constexpr ternary or invoking lambda with if constexpr inside. Since, in c++ is no constexpr ternary and instantly invoking lambda with all possible conditions is not friendly API - there is place for new approach