diff --git a/examples/foreign.cpp b/examples/foreign.cpp index 2b6ce69..470db1a 100644 --- a/examples/foreign.cpp +++ b/examples/foreign.cpp @@ -1,5 +1,6 @@ // -*- compile-command: "make foreign && ./foreign" -*- +// clang++ -g -std=c++11 -I../include ../src/multi_methods.cpp foreign.cpp -o foreign && ./foreign // foreign.cpp // Copyright (c) 2013 Jean-Louis Leroy // Distributed under the Boost Software License, Version 1.0. (See diff --git a/src/multi_methods.cpp b/src/multi_methods.cpp index 3c82953..3b7d5c1 100644 --- a/src/multi_methods.cpp +++ b/src/multi_methods.cpp @@ -123,7 +123,6 @@ namespace yorel { void mm_class::add_to_initialize(mm_class* pc) { YOREL_MM_TRACE(cout << "add to initialize: " << pc << endl); - assert(pc->is_root()); if (!to_initialize) { to_initialize.reset(new unordered_set); @@ -248,7 +247,11 @@ namespace yorel { void initialize() { while (mm_class::to_initialize) { auto pc = *mm_class::to_initialize->begin(); - hierarchy_initializer::initialize(*pc); + if (pc->is_root()) { + hierarchy_initializer::initialize(*pc); + } else { + mm_class::remove_from_initialize(pc); + } } while (multi_method_base::to_initialize) { @@ -284,7 +287,7 @@ namespace yorel { void mm_class::add_multi_method(multi_method_base* pm, int arg) { rooted_here.push_back(mmref { pm, arg }); - add_to_initialize(root); + add_to_initialize(this); } void mm_class::remove_multi_method(multi_method_base* pm) { @@ -311,11 +314,10 @@ namespace yorel { multi_method_base::multi_method_base(const vector& v) : vargs(v) { int i = 0; - for_each(vargs.begin(), vargs.end(), - [&](mm_class* pc) { - YOREL_MM_TRACE(cout << "add mm rooted in " << pc->ti.name() << " argument " << i << "\n"); - pc->add_multi_method(this, i++); - }); + for (auto pc : vargs) { + YOREL_MM_TRACE(cout << "add mm rooted in " << pc->ti.name() << " argument " << i << "\n"); + pc->add_multi_method(this, i++); + } slots.resize(v.size()); }