diff options
Diffstat (limited to 'ACE/contrib/utility/Example/Hetero/Container')
-rw-r--r-- | ACE/contrib/utility/Example/Hetero/Container/Makefile | 24 | ||||
-rw-r--r-- | ACE/contrib/utility/Example/Hetero/Container/container.cpp | 110 |
2 files changed, 134 insertions, 0 deletions
diff --git a/ACE/contrib/utility/Example/Hetero/Container/Makefile b/ACE/contrib/utility/Example/Hetero/Container/Makefile new file mode 100644 index 00000000000..29135f54046 --- /dev/null +++ b/ACE/contrib/utility/Example/Hetero/Container/Makefile @@ -0,0 +1,24 @@ +# file : Example/Hetero/Container/Makefile +# author : Boris Kolpackov <boris@kolpackov.net> +# copyright : Copyright (c) 2002-2003 Boris Kolpackov +# license : http://kolpackov.net/license.html + +root := ../../.. + +include $(root)/BuildRules/Bootstrap.rules + +$(call include, $(root)/BuildRules/Executable.pre.rules) + + +cxx_translation_units := container.cpp + +module_base := container +module_prefix := +module_suffix := + + +CXX_PREPROCESS_FLAGS += -I $(root) + + +$(call include, $(root)/BuildRules/Executable.post.rules) +# $Id$ diff --git a/ACE/contrib/utility/Example/Hetero/Container/container.cpp b/ACE/contrib/utility/Example/Hetero/Container/container.cpp new file mode 100644 index 00000000000..f6ba5560dda --- /dev/null +++ b/ACE/contrib/utility/Example/Hetero/Container/container.cpp @@ -0,0 +1,110 @@ +// file : Example/Hetero/Container/container.cpp +// author : Boris Kolpackov <boris@kolpackov.net> +// copyright : Copyright (c) 2002-2003 Boris Kolpackov +// license : http://kolpackov.net/license.html + +#include "Utility/Hetero/Container.hpp" +#include "Utility/Hetero/TypedContainer.hpp" +#include "Utility/Hetero/Vector.hpp" +#include "Utility/Hetero/Shell.hpp" + +#include <string> +#include <iostream> +#include <algorithm> + +using std::string; + +using std::cout; +using std::cerr; +using std::endl; + +namespace Hetero = Utility::Hetero; + +using Hetero::Container; +using Hetero::TypedContainer; +using Hetero::TypeList; +using Hetero::Shell; + + +struct PrintCore +{ + typedef void RetType; + + template <typename T> + void + operator() (T const& t) + { + cout << t << endl; + } +}; + +typedef Shell<PrintCore> Print; + +void +print (bool b) +{ + cout << (b ? "T" : "NIL") << endl; +} + +int +main () +{ + try + { + Container a (10L); + Container b (true); + Container c (string ("hello")); + + string s = c + string (" world"); + + long l = a + 20L; + + cout << s << "; " << l << endl; + + print (b); + + // + // + // + + typedef + TypedContainer <TypeList<long, bool, string> > + MyContainer; + + MyContainer x (true); + MyContainer y (10L); + MyContainer z (string ("hey dude")); + + Print print; + + print (x); + print (y); + print (z); + + // + // + // + + typedef + Hetero::Vector<long, bool, string> + vector; + + vector v; + v.push_back (10L); + v.push_back (true); + v.push_back (false); + v.push_back (string ("hey")); + + for (vector::iterator i = v.begin (); i != v.end (); i++) + { + print (*i); + } + + std::for_each (v.begin (), v.end (), print); + } + catch (Hetero::Typing const&) + { + cerr << "typing error" << endl; + } +} +//$Id$ |