473,382 Members | 1,445 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,382 software developers and data experts.

How to specially treat the beginning of a type list?

Hi,

The line with the comment "// redundant" is redundant in the sense
that is never used in the main program. However, removing that line
will invalidate the program. I'm wondering if there is any way to
intelligently remove that line while still leaving the program
compilable.

Thanks,
Peng

#include <iostream>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/placeholders.hpp>

class base {
public :
virtual ~base() {}
virtual void accept(base& b) = 0 ;
void visit() { } // redundant
};

template <typename Base, typename T>
class visitor : public Base {
public :
virtual void visit(T &) = 0 ;
using Base::visit;
};

class A;
class B;

typedef boost::mpl::vector<A, BAB;

typedef boost::mpl::fold<AB, base,
visitor<boost::mpl::placeholders::_1, boost::mpl::placeholders::_2>
>::type v;
class A : public v {
public :
void visit(A&) {
std::cout << "A-A" << std::endl;
}
void visit(B&) {
std::cout << "A-B" << std::endl;
}
void accept(base& b) {
static_cast<v&>(b).visit(*this);
}
};

class B : public v {
public :
void visit(A&) {
std::cout << "B-A" << std::endl;
}
void visit(B&) {
std::cout << "B-B" << std::endl;
}
void accept(base& b) {
static_cast<v&>(b).visit(*this);
}
};

int main(){
A a;
B b;
base& x1 = a ;
base& x2 = b ;

x1.accept(x1); // A-A
x2.accept(x1); // A-B
x1.accept(x2); // B-A
x2.accept(x2); // B-B

return EXIT_SUCCESS;
}

Jul 28 '07 #1
4 1407
<Pe*******@gmail.comwrote in message
news:11**********************@i13g2000prf.googlegr oups.com...
Hi,

The line with the comment "// redundant" is redundant in the sense
that is never used in the main program. However, removing that line
will invalidate the program. I'm wondering if there is any way to
intelligently remove that line while still leaving the program
compilable.

Thanks,
Peng

#include <iostream>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/placeholders.hpp>

class base {
public :
virtual ~base() {}
virtual void accept(base& b) = 0 ;
void visit() { } // redundant
};

template <typename Base, typename T>
class visitor : public Base {
public :
virtual void visit(T &) = 0 ;
using Base::visit;
};

class A;
class B;

typedef boost::mpl::vector<A, BAB;

typedef boost::mpl::fold<AB, base,
visitor<boost::mpl::placeholders::_1, boost::mpl::placeholders::_2>
>>::type v;

class A : public v {
public :
void visit(A&) {
std::cout << "A-A" << std::endl;
}
void visit(B&) {
std::cout << "A-B" << std::endl;
}
void accept(base& b) {
static_cast<v&>(b).visit(*this);
}
};

class B : public v {
public :
void visit(A&) {
std::cout << "B-A" << std::endl;
}
void visit(B&) {
std::cout << "B-B" << std::endl;
}
void accept(base& b) {
static_cast<v&>(b).visit(*this);
}
};

int main(){
A a;
B b;
base& x1 = a ;
base& x2 = b ;

x1.accept(x1); // A-A
x2.accept(x1); // A-B
x1.accept(x2); // B-A
x2.accept(x2); // B-B

return EXIT_SUCCESS;
}
You forgot to mark which line was redundant. Which line is it?
Jul 28 '07 #2
Jim Langston wrote:
<Pe*******@gmail.comwrote...
>The line with the comment "// redundant" is redundant in the sense
that is never used in the main program. However, removing that line
will invalidate the program. I'm wondering if there is any way to
intelligently remove that line while still leaving the program
compilable.
[...]
>class base {
public :
virtual ~base() {}
virtual void accept(base& b) = 0 ;
void visit() { } // redundant
^^^^^^^^^
>};
[...]
>
You forgot to mark which line was redundant. Which line is it?
That one.

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Jul 28 '07 #3
Pe*******@gmail.com wrote:
The line with the comment "// redundant" is redundant in the sense
that is never used in the main program. However, removing that line
will invalidate the program. I'm wondering if there is any way to
intelligently remove that line while still leaving the program
compilable.

Thanks,
Peng

#include <iostream>
#include <boost/mpl/fold.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/placeholders.hpp>

class base {
public :
virtual ~base() {}
virtual void accept(base& b) = 0 ;
void visit() { } // redundant
};

template <typename Base, typename T>
class visitor : public Base {
public :
virtual void visit(T &) = 0 ;
using Base::visit;
};
Remove the "using" declaration above, then you also can remove the
declaration of the function void visit().

--
Thomas
http://www.netmeister.org/news/learn2quote.html
Jul 28 '07 #4

Jim Langston wrote in message...
<Pe*******@gmail.comwrote in message...
Hi,
The line with the comment "// redundant" is redundant in the sense
that is never used in the main program.

class base { public :
virtual ~base() {}
virtual void accept(base& b) = 0 ;
void visit() { } // redundant
};

You forgot to mark which line was redundant. Which line is it?
Glad to see I'm not the only one with sight problems. <G>

Hi Jim.
--
Bob R
POVrookie
Jul 28 '07 #5

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

Similar topics

6
by: Pelle Beckman | last post by:
whew. This must be my tenth post or so just this week - thank you to everyone who took the time to answer my questions! Now, I'm helping a friend with an OpenGL application and we need some...
1
by: Reynardine | last post by:
I am calling a C/C++ DLL from C# and I am marshalling the parameters to the API call by doing a type conversion for each parameter. For example, here is my C++ API method : short int XENO_API...
5
by: MLH | last post by:
I have an Access 2.0 app I still use. How best can I list all tables in a combo- box on an Access 2.0 form - just tables beginning with "ABCDE"? Bear in mind that I'm adding new tables to the app...
0
by: Gregory Piñero | last post by:
Hi Wise Python Folk, Here's my code: 'values=%5B1%2C+2%2C+3%5D&labels=%5B1%2C+2%2C+3%5D&type=bar&title=Gregs+Chart+1' Now I just can't figure out what it's giving me for say values? What is...
1
by: dt | last post by:
My understand is that MYSQL only supports indexes on the beginning of a string of data. for example, if you have a list of email addresses, searching for something like '%@yahoo.com' would need...
5
by: walterbyrd | last post by:
The strings start with whitespace, and have a '*' or an alphanumeric character. I need to know how many whitespace characters exist at the beginning of the string.
38
by: joeschnell | last post by:
First week of the current trimester and we've taken a huge leap from writing little code snippets of loops and switches to writing an entire program, and expecting it to work! I, nor anyone else in...
7
tdw
by: tdw | last post by:
Hi all, I've tried to find this answer in the help menu and online but haven't found it: When I type in a field on my form, and then hit backspace to erase what I just typed, my understanding...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.