boost::has_trivial_constructor doesn't work

A

andrew_nuss

Hi,

I'm using the latest version of Intel Linux Compiler, offers boost
built-in. I include <boost/type_traits/has_trivial_constructor.hpp>,
create a simple struct as follows:

struct MyStruct {
// no constructor!
};

and find that expression
boost::has_trivial_constructor<MyStruct>::value is false.

This is too wierd. Isn't that a bug in my boost package?

Thanks,
Andy
 
G

Gennaro Prota

Hi,

I'm using the latest version of Intel Linux Compiler, offers boost
built-in. I include <boost/type_traits/has_trivial_constructor.hpp>,
create a simple struct as follows:

struct MyStruct {
// no constructor!
};

and find that expression
boost::has_trivial_constructor<MyStruct>::value is false.

This is too wierd. Isn't that a bug in my boost package?

Please read the documentation which comes with your boost package
(has_trivial_constructor<> requires help from the compiler).
 
P

Pete Becker

Hi,

I'm using the latest version of Intel Linux Compiler, offers boost
built-in. I include <boost/type_traits/has_trivial_constructor.hpp>,
create a simple struct as follows:

struct MyStruct {
// no constructor!
};

and find that expression
boost::has_trivial_constructor<MyStruct>::value is false.

This is too wierd. Isn't that a bug in my boost package?

Nobody has figured out how to implement has_trivial_constructor without
compiler help. In TR1, it's allowed to always return false. That's
usually a safe fallback -- if you're using it to determine whether you
can use memcpy to initialize an array of that type, answering no means
you won't do any damage. (For more details, see chapter 11 of my book,
"The Standard C++ Library Extensions".)

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 
A

andrew_nuss

Nobody has figured out how to implement has_trivial_constructor without
compiler help. In TR1, it's allowed to always return false. That's
usually a safe fallback -- if you're using it to determine whether you
can use memcpy to initialize an array of that type, answering no means
you won't do any damage. (For more details, see chapter 11 of my book,
"The Standard C++ Library Extensions".)


Well that's good info! I know which classes of mine have trivial
constructors. For those, I inherit from an empty struct called
CtorDtorLess. I have gotten a meta-programming fragment from
Alexandrescu that uses a function with ... argument to distinguish
between structs that inherit from another struct versus not.

Unfortunately, on my compiler, I am getting a warning 1595 cannot pass
POD to elipses. Disabling that warning allows it to work.

Can you tell me what boost replacement there is for determining if a
struct inherits from another? I'm hoping I can use that instead and
avoid the warning.

Andy
 
A

andrew_nuss

I partially answered my own question, use boost::is_base_of<B,
D>::value, but it seems like this is unavailable in the latest Linux
Compiler from Intel.

I #include <boost/type_traits.hpp>, for which there is no complaint,
and then use boost::is_base_of<B, D>::value but the compiler complains
that it can't find is_base_of.

Also, when I #include <boost/type_traits/is_base_of.hpp> I get a
catastrophic error, saying that this include does not exist.

Is this such a recent addition to boost, that it didn't make its way
into the Linux version 9.1.49 that I just downloaded?

Andy
 
P

Pete Becker

I partially answered my own question, use boost::is_base_of<B,
D>::value, but it seems like this is unavailable in the latest Linux
Compiler from Intel.

I think the name in Boost is is_base_and_derived. But you should be
asking about Boost at www.boost.org.

In TR1 it's is_base_of

--

-- Pete
Roundhouse Consulting, Ltd. (www.versatilecoding.com)
Author of "The Standard C++ Library Extensions: a Tutorial and
Reference." (www.petebecker.com/tr1book)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,294
Messages
2,571,511
Members
48,198
Latest member
couriermedicine

Latest Threads

Top