473,325 Members | 2,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

is_virtual_base<B, D> - possible?

While developing my own serialization library, I've found a need to
detect, for a given pair of classes B and D, such that D directly
derives from B, whether B is a virtual or non-virtual base of D. I've
tried a few approaches to developing a template that would be able to
resolve this, trying to use the inability to static_cast virtual bases
to derived classes, and conversion ambiguity in overrides with
covariant return types, but it seems that both approaches are dead-
ends - they aren't usable for SFINAE. And I can't figure out what
other quirks of the language can be used to detect virtual bases. In
fact, is it even possible to do? Perhaps someone could share his
experience in dealing with a similar problem?

May 29 '07 #1
3 1545
On 29 May, 07:45, int...@gmail.com wrote:
While developing my own serialization library, I've found a need to
detect, for a given pair of classes B and D, such that D directly
derives from B, whether B is a virtual or non-virtual base of D. I've
tried a few approaches to developing a template that would be able to
resolve this, trying to use the inability to static_cast virtual bases
to derived classes, and conversion ambiguity in overrides with
covariant return types, but it seems that both approaches are dead-
ends - they aren't usable for SFINAE. And I can't figure out what
other quirks of the language can be used to detect virtual bases. In
fact, is it even possible to do? Perhaps someone could share his
experience in dealing with a similar problem?
#include <boost/type_traits.hpp>

template<class Base, class Derived>
struct is_virtual_base_impl
{
struct In : Derived, virtual Base
{
};
enum { value = sizeof(In) == sizeof(Derived) };
};

template<class Base, class Derived>
struct is_virtual_base
{
enum { value = boost::is_base_and_derived<Base, Derived>::value &&
is_virtual_base_impl<Base, Derived>::value };
};

I'm not sure this will work in all cases. you should check
boost::serialization
library, they must have something like this.

DS

May 31 '07 #2
struct is_virtual_base_impl
{
struct In : Derived, virtual Base
{
};
enum { value = sizeof(In) == sizeof(Derived) };

};
The sizeof() solution is the one I use currently, but it is horribly
hackish - there are no guarantees about how the size of objects
changes (or doesn't) with different flavors of inheritance. It seems
to work with two compilers here, but not only it may not work on some
other one, it can be easily broken by moving to a next version of
those same compilers, so I'm rather uncomfortable with it.

The only thing I can find in Boost is a vague mention of
is_virtual_base in the TODO list for the next version of the
serialization library. No code though, neither in the latest release,
nor in the CVS (including sandbox).

Jun 1 '07 #3
On 1 Jun, 14:41, int...@gmail.com wrote:
struct is_virtual_base_impl
{
struct In : Derived, virtual Base
{
};
enum { value = sizeof(In) == sizeof(Derived) };
};

The sizeof() solution is the one I use currently, but it is horribly
hackish - there are no guarantees about how the size of objects
changes (or doesn't) with different flavors of inheritance. It seems
to work with two compilers here, but not only it may not work on some
other one, it can be easily broken by moving to a next version of
those same compilers, so I'm rather uncomfortable with it.
I'm not quite sure about this solution myself. Unfortunately
every deficiency I can think of is implementation specific
and not C++ standard issue. I was hoping that boost might have
some compiler specific implementations.

on the other hand, it will never answer true if the Base is not
virtually
inherited by Derived, so used in serialization library, it will
always produce correct, albeit maybe not most efficient, code.
The only thing I can find in Boost is a vague mention of
is_virtual_base in the TODO list for the next version of the
serialization library. No code though, neither in the latest release,
nor in the CVS (including sandbox).
hmm. that is not very encouraging to hear. Why not ask at
comp.lib.boost.devel . Maybe someone with more experience
with different compilers has a more general solution.

DS
Jun 4 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Julia Briggs | last post by:
I am struggling to create a PHP function that would take a specified image (JPG, GIF or PNG) from a link, and resize it down to a thumbnail so it will always fit in a 200x250 space. I am hoping...
36
by: rbt | last post by:
Say I have a list that has 3 letters in it: I want to print all the possible 4 digit combinations of those 3 letters: 4^3 = 64 aaaa
20
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to...
7
by: Andrzej | last post by:
Is it possible to call a function which name is given by a string? Let assume that I created a program which call some functions for example void f1(void), void f2(void), void f3(void). ...
2
by: Bhupesh Naik | last post by:
This is a query regarding my problem to make a spell and grammar check possible in text area of a web page. We have aspx pages which are used to construct letters. The browser based screens...
1
by: AAA | last post by:
hi, I'll explain fastly the program that i'm doing.. the computer asks me to enter the cardinal of a set X ( called "dimX" type integer)where X is a table of one dimension and then to fill it...
25
by: Piotr Nowak | last post by:
Hi, Say i have a server process which listens for some changes in database. When a change occurs i want to refresh my page in browser by notyfinig it. I do not want to refresh my page i.e....
4
by: RSH | last post by:
Okay my math skills aren't waht they used to be... With that being said what Im trying to do is create a matrix that given x number of columns, and y number of possible values i want to generate...
7
by: Robert S. | last post by:
Searching some time now for documents on this but still did not find anything about it: Is it possible to replace the entry screen of MS Office Access 2007 - that one presenting that default...
14
by: bjorklund.emil | last post by:
Hello pythonistas. I'm a newbie to pretty much both programming and Python. I have a task that involves writing a test script for every possible combination of preference settings for a software...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.