Andreas Huber | 1 Mar 2006 01:02
Picon
Favicon

[Solution] Re: [statechart] Template States, Compile Error

Hi Dave

The problem you stumbled upon is (or was :-() well known. It was
discussed during review and I even tried to find a workaround for it not
too long ago. The solution is very simple and is even described in the
reference manual under the requirements for the InnerInitial parameter:
<quote>
An mpl::list<> containing models of the SimpleState or State concepts or
instantiations of the shallow_history or deep_history class templates.
If there is only a single inner initial state
_that_is_not_a_template_instantiation_ then it can also be passed
directly, without wrapping it into an mpl::list<>. [...]
</quote>

(_Note_the_underlined_part_). So, the only thing you need to do is to
wrap every templated InnerInitial parameter into an mpl::list and
everything will work as expected (see attached example). The reason why
compilers rightly choke on the code lies in the fact that simple_state
internally checks whether the InnerInitial parameter already is an
mpl::list. This check works perfectly even on forward-declared classes.
However, as soon as InnerInitial is a class template instantiation, for
some reason that template needs to be fully instantiated. The problem is
described in more detail here:
<http://article.gmane.org/gmane.comp.lib.boost.devel/128741>

I guess it was simply a little too late yesterday, sorry...

#include <boost/statechart/state_machine.hpp>
#include <boost/statechart/simple_state.hpp>
#include <boost/mpl/list.hpp>
(Continue reading)

Lucio Flores | 1 Mar 2006 04:27
Picon
Favicon

lambda syntax


So as an exercise, I'm trying to use a lambda expression that applies the first
argument twice on it's second argument. 

typedef mpl::apply<_1, mpl::apply<_1, _2>::type>::type twice_type;

Then I instance this lambda function on boost::add_pointer and int

typedef mpl::apply<twice_type, boost::add_pointer<_1>, int>::type result_type;

But using boost::is_same, I've found that result_type==int, not int** as
expected. Can someone see why?

-------------------------------------------

Manson: My philosophy is:  Don't think.  I don't believe in the mind that you think with and scheme with.  I
don't believe in words.

Reporter: If you don't believe in words, why do you use so many of them?

Manson: Words are symbols.  All I'm doing is jumbling the symbols in your brain.  Everything is symbolic. 
Symbols are just connections in your brain.  Even your body is a symbol.

__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 
RIVASSEAU Jean Noel | 1 Mar 2006 09:52

Re: Serialization : unregistered_cast & otherquestions


This is true.  But this is a minor in my opinion. The root cause of this
situation is that linkers complain about multiply defined functions
- even when those functions are identical.  Maybe someday we'll
have smarter linkers - but until then this works quite well.  It does
require that one spend a little time explicitly considering code
instantiation.  But this isn't necessarily bad.  Letting the compile/linker
do all the work will lead to code bloat and compilation time problems.

I definitely agree with you - smarter linkers would be a big gift. Right now dealing with templates is
generally a pain because of linker issues, and requires that one takes a lot of precaution to insure
everything compiles/links smoothly.

I had the same problems when using the BGL last year, and also had to resort to manual template instantiation
in the end.

Jean-Noël
RIVASSEAU Jean Noel | 1 Mar 2006 09:55

Re: serialization: errata: even manual instantiationisimpossible


//  my_class_serialization.cpp or my_class.cpp or .. *.cpp

#include <boost/archive/xml_iarchive.hpp>
.... // all archives you might whant to use here.

template<class Archive>
serialize(Archive &ar, my_class &t....){
    ... serialization for class my_class
}

#include "my_class.hpp"

// explict instantiation here for all the archives which interest me

template
void serialize<boost::archive::xml_iarchive, my_class>;
... // explicit instantiation for all other archives you might use here.

I notice you still include the archive headers in my_class_serialization.cpp. In that case, you do not
have in fact to manually instantiate templates, since my_class_serialization.cpp includes 
"my_class.hpp" which includes export.hpp and maybe BOOST_CLASS_EXPORT after the archive headers
included in class_serialization.cpp, so template instantiation will occure anyway.

Anyway let's close this topic. I understood what the point was.

Jean-Noël
RIVASSEAU Jean Noel | 1 Mar 2006 09:59

Serialization: docs regarding abstract base class

I quote the Boost serialization docs:

 

When serializing an object through a pointer to its base class and that base class is abstract (i.e. has at least one virtual function assigned a value of 0), A compile error will be emitted. This is addressable in one over several ways:

  • remove the =0 in the base classes so that the base class is no longer abstract.

  • implement is_abstract for your compiler. (code written according to the C++ standard is included with this library. But it is known to fail on several compilers.

  • use the macro BOOST_IS_ABSTRACT(my_class) to indicate that the class is an abstract base class. This will cause the compiler to avoid generating code that causes this error.

I still do not understand part 2 of this advice, Robert. Could you explain?

 

Jean-Noël

 

Ps: as already mentioned, part 3 does not change anything for me, and I’d like to avoid the solution of part 1 since I do want the base class to be abstract.

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
RIVASSEAU Jean Noel | 1 Mar 2006 10:59

serialization: found a (satisfactory) way to avoid the abstract class problem linking problem

Hello Robert,

 

I found a way to avoid the link problem when dealing with a base abstract class, that maintains the base class abstract :

 

I just manually instantiated the save/load functions for the abstract base class. They should have been instantiated by BOOST_CLASS_EXPORT, but this apparently does not work with abstract base classes; however manual instantiation works just fine.

 

So I now have only one more problem (unfortunately, very serious), that happens with the serialization of std::vector containing pointers.

 

Jean-Noël

_______________________________________________
Boost-users mailing list
Boost-users <at> lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
Johan Nilsson | 1 Mar 2006 11:32
Picon

[Parameter] Constructors and more

Hi,

I've just started playing around with Boost.Parameter. I'm in the progress 
of wrapping a legacy C library and some of the structs used have plenty of 
members, most of which have reasonable defaults. I thought that the 
Parameter library would be a nice fit here, but ended up with a couple of 
questions:

1. How can I define constructor for a class taking named parameters, without 
using the double parentheses syntax? The following basic idea works, but is 
ugly:

---
...
BOOST_PARAMETER_KEYWORD(tag, minVal)
BOOST_PARAMETER_KEYWORD(tag, maxVal)

struct Foo
{
        template<typename ArgPack>
        Foo(ArgPack& args)
        {
            m_minVal = args[minVal|0];
            m_maxVal = args[maxVal|100];
        }
    ...
};

void bar()
{
    Foo foo(( minVal = 1, maxVal = 2)); // Note double parens
}
---

I've experimented some with defining a parameter::parameters specification 
and use (the undocumented) BOOST_PARAMETER_MEMFUN, but that obviously 
doesn't work (forwarding, return values and constructors don't mix). It 
should be possible (I think) to define a BOOST_PARAMETER_CTOR macro that 
generate the ctor overloads and forwards to a setter method instead of the 
other way around.

I guess I could create a free or static member function that constructs an 
object, but that would either force me to create heap-based objects, or 
invoke potentially expensive copy ctors.

2. Is there a way of detecting whether an argument was passed using position 
or name? Or, even better, is there a way of restricting the arguments to 
only be passed by name using the parameters specification?

3. Not a question really, but having a default arity of 5 seems awfully low 
to me. I hit that limit on first usage, and as the named parameters are 
supposed to be used in the interface of my wrapping library, forcing users 
to define BOOST_PARAMETER_MAX_ARITY "globally" feels a bit like asking for 
someone coming up and asking me to decode some compile errors.

[I'm using the latest cvs head of boost, in combination with VC 8.0]

Regards,

Johan Nilsson
Tobias Combe | 1 Mar 2006 11:59
Picon
Favicon

Re: problem with serialization of pure virtual

I'm using gcc 3.3.5
and now i get the following error:
with oa << event; :
boost/serialization/access.hpp: In static member function `static void
   boost::serialization::access::serialize(Archive&, T&, unsigned int) [with
   Archive = boost::archive::text_oarchive, T = DataNode]':
boost/serialization/serialization.hpp:81:   instantiated from `void 
boost::serialization::serialize(Archive&, T&, unsigned int) [with 
Archive = boost::archive::text_oarchive, T = DataNode]'
boost/serialization/serialization.hpp:140:   instantiated from `void 
boost::serialization::serialize_adl(Archive&, T&, unsigned int) [with 
Archive = boost::archive::text_oarchive, T = DataNode]'
boost/archive/detail/oserializer.hpp:148:   instantiated from `void 
boost::archive::detail::oserializer<Archive, 
T>::save_object_data(boost::archive::detail::basic_oarchive&, const 
void*) const [with Archive = boost::archive::text_oarchive, T = DataNode]'
boost/mpl/if.hpp:67:   instantiated from here
boost/serialization/access.hpp:109: error: `serialize' undeclared (first use
   this function)
boost/serialization/access.hpp:109: error: (Each undeclared identifier is
   reported only once for each function it appears in.)

with //oa << event; :
IDSNet/Sensor.o(.text+0x367): In function `Sensor::~Sensor 
[not-in-charge]()':
Sensor.cc: undefined reference to `vtable for Sensor'
IDSNet/Sensor.o(.text+0x3c9): In function `Sensor::~Sensor [in-charge]()':
Sensor.cc: undefined reference to `vtable for Sensor'
IDSNet/Sensor.o(.text+0x42b): In function `Sensor::~Sensor [in-charge 
deleting]()':
Sensor.cc: undefined reference to `vtable for Sensor'
IDSNet/Sensor.o(.gnu.linkonce.r._ZTI10PollSensor+0x8): undefined 
reference to `typeinfo for Sensor'
IDSNet/Sensor.o(.gnu.linkonce.r._ZTI10PushSensor+0x8): undefined 
reference to `typeinfo for Sensor'
IDSNet/Sensor.o(.gnu.linkonce.t._ZN6SensorC2Ev+0xb): In function 
`Sensor::Sensor[not-in-charge]()':
Sensor.cc: undefined reference to `vtable for Sensor'
Marcio Paim de Aquino | 1 Mar 2006 14:34
Picon

[BGL] Dijkstra Shortest Paths

Hello all,

does anyone know how to make a custom dijkstra visitor that ends the 
algorithm when
it finds the path between two especified vertexes?

Thanks,

Marcio
Michael Kettner | 1 Mar 2006 14:54
Picon

Re: [BGL] Dijkstra Shortest Paths

Hi Marcio!

On Wednesday 29 March 2006 14:43, Marcio Paim de Aquino wrote:
> Hello all,
>
> does anyone know how to make a custom dijkstra visitor that ends the
> algorithm when
> it finds the path between two especified vertexes?

You might read the manual. This is from
	http://www.boost.org/libs/graph/doc/faq.html

How do I perform an early exit from an algorithm such as BFS?

 Create a visitor that throws an exception when you want to cut off the
search, then put your call to breadth_first_search inside of an appropriate
try/catch block. This strikes many programmers as a misuse of exceptions,
however, much thought was put into the decision to have exceptions has the
preferred way to exit early. See boost email discussions for more details.

Regards,
 Michael

> Thanks,
>
> Marcio

Gmane