This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 115e. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2024-11-11


2274. Generic lambda capture vs constexpr if

Section: 8.5.2  [stmt.if]     Status: NAD     Submitter: Richard Smith     Date: 2016-06-20

Consider:

  template<typename Iter> void f(Iter a, Iter b) {
    const int v = 10;
    auto do_something = [&] (auto thing) {
      if constexpr (is_random_access_iterator<Iter> && is_integral<decltype(thing)>)
        *(a + 1) = v;
     };
    do_something(5);
    do_something("foo");
  } 

Determining whether v is captured requires instantiating the "if constexpr", but that results in a hard error for a statement that will eventually be discarded.

Rationale (February, 2018):

These questions were resolved by the adoption of paper P0588R1 at the November, 2017 meeting.