[PATCH] [libc++] Const qualify __mem_fn call operator
Peter Collingbourne
peter at pcc.me.uk
Tue Oct 29 17:46:10 PDT 2013
Hi howard.hinnant,
QOI improvement.
http://llvm-reviews.chandlerc.com/D2059
Files:
include/__functional_03
include/functional
test/utilities/function.objects/func.memfn/member_data.pass.cpp
test/utilities/function.objects/func.memfn/member_function.pass.cpp
test/utilities/function.objects/func.memfn/member_function_const.pass.cpp
test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp
test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp
Index: include/__functional_03
===================================================================
--- include/__functional_03
+++ include/__functional_03
@@ -33,28 +33,28 @@
// invoke
typename __invoke_return<type>::type
- operator() ()
+ operator() () const
{
return __invoke(__f_);
}
template <class _A0>
typename __invoke_return0<type, _A0>::type
- operator() (_A0& __a0)
+ operator() (_A0& __a0) const
{
return __invoke(__f_, __a0);
}
template <class _A0, class _A1>
typename __invoke_return1<type, _A0, _A1>::type
- operator() (_A0& __a0, _A1& __a1)
+ operator() (_A0& __a0, _A1& __a1) const
{
return __invoke(__f_, __a0, __a1);
}
template <class _A0, class _A1, class _A2>
typename __invoke_return2<type, _A0, _A1, _A2>::type
- operator() (_A0& __a0, _A1& __a1, _A2& __a2)
+ operator() (_A0& __a0, _A1& __a1, _A2& __a2) const
{
return __invoke(__f_, __a0, __a1, __a2);
}
Index: include/functional
===================================================================
--- include/functional
+++ include/functional
@@ -1221,7 +1221,7 @@
template <class... _ArgTypes>
_LIBCPP_INLINE_VISIBILITY
typename __invoke_return<type, _ArgTypes...>::type
- operator() (_ArgTypes&&... __args)
+ operator() (_ArgTypes&&... __args) const
{
return __invoke(__f_, _VSTD::forward<_ArgTypes>(__args)...);
}
Index: test/utilities/function.objects/func.memfn/member_data.pass.cpp
===================================================================
--- test/utilities/function.objects/func.memfn/member_data.pass.cpp
+++ test/utilities/function.objects/func.memfn/member_data.pass.cpp
@@ -32,6 +32,8 @@
assert(a.data_ == 6);
const A* cap = ap;
assert(f(cap) == f(ap));
+ const F& cf = f;
+ assert(cf(ap) == f(ap));
}
}
Index: test/utilities/function.objects/func.memfn/member_function.pass.cpp
===================================================================
--- test/utilities/function.objects/func.memfn/member_function.pass.cpp
+++ test/utilities/function.objects/func.memfn/member_function.pass.cpp
@@ -31,6 +31,8 @@
assert(f(a) == 'a');
A* ap = &a;
assert(f(ap) == 'a');
+ const F& cf = f;
+ assert(cf(ap) == 'a');
}
}
@@ -43,6 +45,8 @@
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 @@
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');
}
}
Index: test/utilities/function.objects/func.memfn/member_function_const.pass.cpp
===================================================================
--- test/utilities/function.objects/func.memfn/member_function_const.pass.cpp
+++ test/utilities/function.objects/func.memfn/member_function_const.pass.cpp
@@ -33,6 +33,8 @@
assert(f(ap) == 'a');
const A* cap = &a;
assert(f(cap) == 'a');
+ const F& cf = f;
+ assert(cf(ap) == 'a');
}
}
@@ -47,6 +49,8 @@
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 @@
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');
}
}
Index: test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp
===================================================================
--- test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp
+++ test/utilities/function.objects/func.memfn/member_function_const_volatile.pass.cpp
@@ -33,6 +33,8 @@
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 @@
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 @@
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');
}
}
Index: test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp
===================================================================
--- test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp
+++ test/utilities/function.objects/func.memfn/member_function_volatile.pass.cpp
@@ -33,6 +33,8 @@
assert(f(ap) == 'a');
volatile A* cap = &a;
assert(f(cap) == 'a');
+ const F& cf = f;
+ assert(cf(ap) == 'a');
}
}
@@ -47,6 +49,8 @@
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 @@
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');
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2059.1.patch
Type: text/x-patch
Size: 5353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131029/d9f0d3a7/attachment.bin>
More information about the cfe-commits
mailing list