Title
Generic lambda capture vs constexpr if
Status
nad
Section
8.5.2 [stmt.if]
Submitter
Richard Smith

Created on 2016-06-20.00:00:00 last changed 83 months ago

Messages

Date: 2018-02-15.00:00:00

Rationale (February, 2018):

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

Date: 2022-11-20.07:54:16

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.

History
Date User Action Args
2018-02-27 00:00:00adminsetmessages: + msg6011
2018-02-27 00:00:00adminsetstatus: open -> nad
2016-06-20 00:00:00admincreate