Mirror reflection library - Lagoon run-time layer 0.5.13

lagoon/example/for_each_04.cpp

This example shows the usage of the namespace reflection functions and range for-each utility with lambda functions and the only_if range adapter

Copyright 2008-2010 Matus Chochlik. Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

#include <mirror/mirror.hpp>
#include <lagoon/lagoon.hpp>
#include <lagoon/range/for_each.hpp>
#include <lagoon/range/only_if.hpp>
#include <iostream>

int main(void)
{
    using namespace lagoon;
    //
    // get the members of the global scope and filter only those
    // satisfying the predicate (the first lambda function)
    // (i.e. meta-objects for which the is_namespace member
    // function returns true) and call the second lambda function
    // on each element of the resulting range
    for_each(
        only_if(
            reflected_global_scope()->members(),
            [](const shared<meta_named_scoped_object>& member)
            {
                return member->is_namespace();
            }
        ),
        [](const shared<meta_named_scoped_object>& member)
        {
            std::cout
                << member->self()->construct_name()
                << " "
                << member->base_name()
                << std::endl;
        }
    );
    return 0;
}

/* Example of output:
namespace std
namespace boost
*/

Copyright © 2006-2011 Matus Chochlik, University of Zilina, Zilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Fri Dec 16 2011 by Doxygen (version 1.7.3).
Important note: Although the 'boostified' version of Mirror uses the Boost C++ libraries Coding Guidelines and is implemented inside of the boost namespace, it IS NOT an officially reviewed and accepted Boost library. Mirror is being developed with the intention to be submitted for review for inclusion to the Boost C++ libraries.