45 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9 10// <functional>11 12// template<class R, class T> constexpr unspecified mem_fn(R T::*) noexcept; // constexpr in C++2013 14#include <functional>15#include <cassert>16 17struct A18{19 double data_;20};21 22template <class F>23void24test(F f)25{26 {27 A a;28 f(a) = 5;29 assert(a.data_ == 5);30 A* ap = &a;31 f(ap) = 6;32 assert(a.data_ == 6);33 const A* cap = ap;34 assert(f(cap) == f(ap));35 f(cap) = 7;36 }37}38 39int main(int, char**)40{41 test(std::mem_fn(&A::data_));42 43 return 0;44}45