From a4c0d87a84b5d324726b334d10fe2f8c24215fad Mon Sep 17 00:00:00 2001 From: Peter Collingbourne Date: Wed, 22 Jan 2014 22:56:52 +0000 Subject: [PATCH] Const qualify __mem_fn call operator QOI improvement. Differential Revision: http://llvm-reviews.chandlerc.com/D2059 git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@199848 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__functional_03 | 8 ++++---- include/functional | 2 +- .../function.objects/func.memfn/member_data.pass.cpp | 2 ++ .../function.objects/func.memfn/member_function.pass.cpp | 6 ++++++ .../func.memfn/member_function_const.pass.cpp | 6 ++++++ .../func.memfn/member_function_const_volatile.pass.cpp | 6 ++++++ .../func.memfn/member_function_volatile.pass.cpp | 6 ++++++ 7 files changed, 31 insertions(+), 5 deletions(-) diff --git a/include/__functional_03 b/include/__functional_03 index f9a3d9766..258260173 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 d40f70af4..891ed460a 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 048fca4d9..dff211c60 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 01a5f8e55..4096bd814 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 978f9f094..be22443e9 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 1e00b4d6b..329ac16a8 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 4d0654a9f..743ded994 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'); } }