By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,421 Members | 1,127 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,421 IT Pros & Developers. It's quick & easy.

boost::has_trivial_constructor doesn't work

P: n/a
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

Jun 2 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Sat, 02 Jun 2007 10:46:55 -0700, an*********@yahoo.com wrote:
>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).

--
Gennaro Prota -- C++ Developer, For Hire
https://sourceforge.net/projects/breeze/
(replace 'address' with 'name.surname' to mail)
Jun 2 '07 #2

P: n/a
an*********@yahoo.com wrote:
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)
Jun 2 '07 #3

P: n/a
On Jun 2, 2:42 pm, Pete Becker <p...@versatilecoding.comwrote:
andrew_n...@yahoo.com wrote:
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".)

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

Jun 2 '07 #4

P: n/a
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.hppI 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

Jun 2 '07 #5

P: n/a
an*********@yahoo.com wrote:
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)
Jun 2 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.