C++ Logo

std-proposals

Advanced search

Re: [std-proposals] if () {typedef x y;}

From: Thiago Macieira <thiago_at_[hidden]>
Date: Sun, 01 May 2022 14:10:44 -0700
On Sunday, 1 May 2022 01:34:01 PDT Wilhelm M via Std-Proposals wrote:
> Isn't this std::conditional?
>
>
> typedef std::conditional<cond, int, double> type;
>
> https://en.cppreference.com/w/cpp/types/conditional

Another trick is with auto and lambda:

  auto c = []() {
        if constexpr (cond)
            return 1;
        else
            return 1.0;
  };
  // c is either int or double, depending on the condition.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering

Received on 2022-05-01 21:10:46