"Fossies" - the Fresh Open Source Software Archive

Member "libsigc++-2.10.2/tests/test_retype_return.cc" (5 May 2019, 1515 Bytes) of package /linux/misc/libsigc++-2.10.2.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 // -*- c++ -*-
    2 /* Copyright 2002, The libsigc++ Development Team
    3  *  Assigned to public domain.  Use as you wish without restriction.
    4  */
    5 
    6 #include "testutilities.h"
    7 #include <sigc++/adaptors/retype_return.h>
    8 #include <sigc++/functors/slot.h>
    9 #include <sstream>
   10 #include <cstdlib>
   11 
   12 namespace
   13 {
   14 std::ostringstream result_stream;
   15 
   16 struct foo : public sigc::functor_base
   17 {
   18   typedef float result_type;
   19 
   20   float operator()(int i)
   21   {
   22     result_stream << "foo(int " << i << ") ";
   23     return i;
   24   }
   25 
   26   float operator()(float i)
   27   {
   28     result_stream << "foo(float " << i << ") ";
   29     return i * 5;
   30   }
   31 };
   32 
   33 struct bar : public sigc::trackable, public sigc::functor_base
   34 {
   35   typedef int result_type;
   36 
   37   int operator()(int i)
   38   {
   39     result_stream << "bar(int " << i << ")";
   40     return i;
   41   }
   42 };
   43 
   44 } // end anonymous namespace
   45 
   46 int main(int argc, char* argv[])
   47 {
   48   auto util = TestUtilities::get_instance();
   49 
   50   if (!util->check_command_args(argc, argv))
   51     return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
   52 
   53   // retype_return<int>
   54   result_stream << sigc::retype_return<int>(foo())(1.234f);
   55   util->check_result(result_stream, "foo(float 1.234) 6");
   56 
   57   // retype_return<void> / hide_return
   58   sigc::slot<void, int> sl;
   59   sl = sigc::retype_return<void>(bar());
   60   sl(5);
   61   util->check_result(result_stream, "bar(int 5)");
   62 
   63   sl = sigc::hide_return(bar());
   64   sl(6);
   65   util->check_result(result_stream, "bar(int 6)");
   66 
   67   return util->get_result_and_delete_instance() ? EXIT_SUCCESS : EXIT_FAILURE;
   68 }