X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=blobdiff_plain;f=libstdc%2B%2B-v3%2Ftestsuite%2Ftr1%2F3_function_objects%2Ffunction%2F5.cc;fp=libstdc%2B%2B-v3%2Ftestsuite%2Ftr1%2F3_function_objects%2Ffunction%2F5.cc;h=1b49c30330803704a724782f369bf391e1234347;hb=6fed43773c9b0ce596dca5686f37ac3fc0fa11c0;hp=0000000000000000000000000000000000000000;hpb=27b11d56b743098deb193d510b337ba22dc52e5c;p=msp430-gcc.git diff --git a/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc b/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc new file mode 100644 index 00000000..1b49c303 --- /dev/null +++ b/libstdc++-v3/testsuite/tr1/3_function_objects/function/5.cc @@ -0,0 +1,106 @@ +// 2005-01-15 Douglas Gregor +// +// Copyright (C) 2005, 2009 Free Software Foundation, Inc. +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING3. If not see +// . + +// 3.7.2 polymorphic function object wrapper +#include +#include +#include + +using namespace __gnu_test; + +bool test __attribute__((unused)) = true; + +// Put member pointers into function<> wrappers +void test05() +{ + using std::tr1::function; + + X x; + x.bar = 17; + + function frm(&X::bar); + VERIFY( frm ); + VERIFY( frm(x) == 17 ); + VERIFY( typeid(int X::*) == frm.target_type() ); + VERIFY( *frm.target() == &X::bar ); + + function fr(&X::foo); + VERIFY( fr ); + VERIFY( fr(x) == 1 ); + VERIFY( typeid(int (X::*)()) == fr.target_type() ); + VERIFY( *fr.target() == &X::foo ); + + function frc(&X::foo_c); + VERIFY( frc ); + VERIFY( frc(x) == 2 ); + VERIFY( typeid(int (X::*)() const) == frc.target_type() ); + VERIFY( *frc.target() == &X::foo_c ); + + function frv(&X::foo_v); + VERIFY( frv ); + VERIFY( frv(x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == frv.target_type() ); + VERIFY( *frv.target() == &X::foo_v ); + VERIFY( frv.target() == 0 ); + + function frcv(&X::foo_cv); + VERIFY( frcv ); + VERIFY( frcv(x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == frcv.target_type() ); + VERIFY( *frcv.target() == &X::foo_cv ); + VERIFY( frcv.target() == 0 ); + + function grm(&X::bar); + VERIFY( grm ); + VERIFY( grm(&x) == 17 ); + VERIFY( typeid(int X::*) == grm.target_type() ); + VERIFY( *grm.target() == &X::bar ); + + function gr(&X::foo); + VERIFY( gr ); + VERIFY( gr(&x) == 1 ); + VERIFY( typeid(int (X::*)()) == gr.target_type() ); + VERIFY( *gr.target() == &X::foo ); + + function grc(&X::foo_c); + VERIFY( grc ); + VERIFY( grc(&x) == 2 ); + VERIFY( typeid(int (X::*)() const) == grc.target_type() ); + VERIFY( *grc.target() == &X::foo_c ); + + function grv(&X::foo_v); + VERIFY( grv ); + VERIFY( grv(&x) == 3 ); + VERIFY( typeid(int (X::*)() volatile) == grv.target_type() ); + VERIFY( *grv.target() == &X::foo_v ); + VERIFY( grv.target() == 0 ); + + function grcv(&X::foo_cv); + VERIFY( grcv ); + VERIFY( grcv(&x) == 4 ); + VERIFY( typeid(int (X::*)() const volatile) == grcv.target_type() ); + VERIFY( *grcv.target() == &X::foo_cv ); + VERIFY( grcv.target() == 0 ); +} + +int main() +{ + test05(); + return 0; +}