diff --git a/include/__functional_03 b/include/__functional_03 index f9a3d976..25826017 100644 --- a/include/__functional_03 +++ b/include/__functional_03 @@ -33,28 +33,28 @@ public: // invoke typename __invoke_return::type - operator() () + operator() () const { return __invoke(__f_); } template typename __invoke_return0::type - operator() (_A0& __a0) + operator() (_A0& __a0) const { return __invoke(__f_, __a0); } template typename __invoke_return1::type - operator() (_A0& __a0, _A1& __a1) + operator() (_A0& __a0, _A1& __a1) const { return __invoke(__f_, __a0, __a1); } template typename __invoke_return2::type - operator() (_A0& __a0, _A1& __a1, _A2& __a2) + operator() (_A0& __a0, _A1& __a1, _A2& __a2) const { return __invoke(__f_, __a0, __a1, __a2); } diff --git a/include/functional b/include/functional index d40f70af..891ed460 100644 --- a/include/functional +++ b/include/functional @@ -1221,7 +1221,7 @@ public: template _LIBCPP_INLINE_VISIBILITY typename __invoke_return::type - operator() (_ArgTypes&&... __args) + operator() (_ArgTypes&&... __args) const { return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...); } diff --git a/test/utilities/function.objects/func.memfn/member_data.pass.cpp b/test/utilities/function.objects/func.memfn/member_data.pass.cpp index 048fca4d..dff211c6 100644 --- a/test/utilities/function.objects/func.memfn/member_data.pass.cpp +++ b/test/utilities/function.objects/func.memfn/member_data.pass.cpp @@ -32,6 +32,8 @@ test(F f) assert(a.data_ == 6); const A* cap = ap; assert(f(cap) == f(ap)); + const F& cf = f; + assert(cf(ap) == f(ap)); } } diff --git a/test/utilities/function.objects/func.memfn/member_function.pass.cpp b/test/utilities/function.objects/func.memfn/member_function.pass.cpp index 01a5f8e5..4096bd81 100644 --- a/test/utilities/function.objects/func.memfn/member_function.pass.cpp +++ b/test/utilities/function.objects/func.memfn/member_function.pass.cpp @@ -31,6 +31,8 @@ test0(F f) assert(f(a) == 'a'); A* ap = &a; assert(f(ap) == 'a'); + const F& cf = f; + assert(cf(ap) == 'a'); } } @@ -43,6 +45,8 @@ test1(F f) assert(f(a, 1) == 'b'); A* ap = &a; assert(f(ap, 2) == 'b'); + const F& cf = f; + assert(cf(ap, 2) == 'b'); } } @@ -55,6 +59,8 @@ test2(F f) assert(f(a, 1, 2) == 'c'); A* ap = &a; assert(f(ap, 2, 3.5) == 'c'); + const F& cf = f; + assert(cf(ap, 2, 3.5) == 'c'); } } diff --git a/test/utilities/function.objects/func.memfn/member_function_const.pass.cpp b/test/utilities/function.objects/func.memfn/member_function_const.pass.cpp index 978f9f09..be22443e 100644 --- a/test/utilities/function.objects/func.memfn/member_function_const.pass.cpp +++ b/test/utilities/function.objects/func.memfn/member_function_const.pass.cpp @@ -33,6 +33,8 @@ test0(F f) assert(f(ap) == 'a'); const A* cap = &a; assert(f(cap) == 'a'); + const F& cf = f; + assert(cf(ap) == 'a'); } } @@ -47,6 +49,8 @@ test1(F f) assert(f(ap, 2) == 'b'); const A* cap = &a; assert(f(cap, 2) == 'b'); + const F& cf = f; + assert(cf(ap, 2) == 'b'); } } @@ -61,6 +65,8 @@ test2(F f) assert(f(ap, 2, 3.5) == 'c'); const A* cap = &a; assert(f(cap, 2, 3.5) == 'c'); + const F& cf = f; + assert(cf(ap, 2, 3.5) == 'c'); } } diff --git a/test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp b/test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp index 1e00b4d6..329ac16a 100644 --- a/test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp +++ b/test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp @@ -33,6 +33,8 @@ test0(F f) assert(f(ap) == 'a'); const volatile A* cap = &a; assert(f(cap) == 'a'); + const F& cf = f; + assert(cf(ap) == 'a'); } } @@ -47,6 +49,8 @@ test1(F f) assert(f(ap, 2) == 'b'); const volatile A* cap = &a; assert(f(cap, 2) == 'b'); + const F& cf = f; + assert(cf(ap, 2) == 'b'); } } @@ -61,6 +65,8 @@ test2(F f) assert(f(ap, 2, 3.5) == 'c'); const volatile A* cap = &a; assert(f(cap, 2, 3.5) == 'c'); + const F& cf = f; + assert(cf(ap, 2, 3.5) == 'c'); } } diff --git a/test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp b/test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp index 4d0654a9..743ded99 100644 --- a/test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp +++ b/test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp @@ -33,6 +33,8 @@ test0(F f) assert(f(ap) == 'a'); volatile A* cap = &a; assert(f(cap) == 'a'); + const F& cf = f; + assert(cf(ap) == 'a'); } } @@ -47,6 +49,8 @@ test1(F f) assert(f(ap, 2) == 'b'); volatile A* cap = &a; assert(f(cap, 2) == 'b'); + const F& cf = f; + assert(cf(ap, 2) == 'b'); } } @@ -61,6 +65,8 @@ test2(F f) assert(f(ap, 2, 3.5) == 'c'); volatile A* cap = &a; assert(f(cap, 2, 3.5) == 'c'); + const F& cf = f; + assert(cf(ap, 2, 3.5) == 'c'); } }