473,400 Members | 2,163 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,400 software developers and data experts.

compile time function selection

Is it possible using Boost mpl library:-

Assume any class implementing a function "connect" with two arugments of
fixed types

class protocol1
{

connect(T0 & t0, T1 &t1 ){..} //fixed types T0 and T1
};

class protocol2
{

connect(T2 & t0, T3 &t1 ){..} // Fixed types T2 and T3
};
Now a function say "connect_protocols" which take two protocols of above
mentioned protocol types

template<typename P0, typename P1>
connect_protocols(P0& p0, P1 & p1)
{..}
What is requires in the body of "connect_protocols" function is a checking
meachimism to use correct connect function avilable from one of the class
(protocol1 or protocol2) without genrating the compile time error.

However if no appropriate connect function is avilable (after checking both
the protocol classes) then genrate compile time error.

Is it possible?
Abhsishek
Jul 27 '05 #1
2 3944
Abhishek Saksena wrote:
Is it possible using Boost mpl library:-
It's not needed here.
Assume any class implementing a function "connect" with two arugments of
fixed types

class protocol1
{

connect(T0 & t0, T1 &t1 ){..} //fixed types T0 and T1
};

class protocol2
{

connect(T2 & t0, T3 &t1 ){..} // Fixed types T2 and T3
};
Now a function say "connect_protocols" which take two protocols of above
mentioned protocol types

template<typename P0, typename P1>
connect_protocols(P0& p0, P1 & p1)
{..}
You forgot to state the return type of the function.
What is requires in the body of "connect_protocols" function is a checking
meachimism to use correct connect function avilable from one of the class
(protocol1 or protocol2) without genrating the compile time error.

However if no appropriate connect function is avilable (after checking both
the protocol classes) then genrate compile time error.

Is it possible?


It is. Just add factory functions that take the same arguments as your
protocol classes's constructors do:

protocol1 create(T0 & t0, T1 &t1) { return protocol1(t0, t1); }
// the same for protocol2

template<typename P0, typename P1>
void connect_protocols(P0& p0, P1 & p1)
{
create(p0, p1);
}

Jul 27 '05 #2
>
What is requires in the body of "connect_protocols" function is a checking
meachimism to use correct connect function avilable from one of the class
(protocol1 or protocol2) without genrating the compile time error.

However if no appropriate connect function is avilable (after checking both
the protocol classes) then genrate compile time error.

Is it possible?


Have you tried template specialisation?
I'm not sure if I read correctly what you asked but the following might
be a solution to your problem.

template<class T, class U>
void connect_protocols(T &First, T &Second);

template<>
void connect_protocols(P0 &First, P1 &Second)
{
// perform connect here
}

template<>
void connect_protocols(P2 &First, P3 &Second)
{
// perform connect here
}

This should result in an compile time error unless you fill in the
correct protocols.

Jul 27 '05 #3

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

Similar topics

17
by: newbiecpp | last post by:
I have hard time to understand run-time environment. Let assume that I have a program that has a simple variable alpha. When this variable is statically allocated, the compiler can use the...
4
by: M. Uppal | last post by:
How do i convert fraction to time in c#. I need to convert 0.25 to time. Excel does this by using Selection.NumberFormat = "h:mm:ss;@" of the Cell Format function. thanks, M. Uppal
1
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a...
3
by: Saxman | last post by:
I need to copy/paste in Excel, but with a delay built in between each copy/paste operation. Below is the code which gives me a compile error on the 2nd Sub Delay(). It is a simple copy from...
10
by: rob.iverson | last post by:
We ran into this problem and I can't see why the compilers (Sun One Studio 8 and g++ 2.95) think it's an error: ------------------- class A { public: void foo();
2
by: ABC | last post by:
How to speed up compile in VS 2005 IDE? Our solution have many projects, when I only modified a file, I want only to compile the modified project, not need to compile all projects. It spend...
11
by: Trent | last post by:
Running this I see that on first run, both bubble and selection sort have 9 sort counts while insertion sort has ZERO. With a sorted list, should this be ZERO for all? Also bsort and Ssort have...
12
by: Ioannis Vranos | last post by:
Perhaps a mechanism can be introduced in the C++0x/1x standard, something simple like defining a function as: void somefunc(void) throw() { // ... }
27
by: CodeMonk3y | last post by:
gotta question on sizeof keyword does the sizeof keyword calcuates the size at compile time or run time ?? -- Posted on news://freenews.netfront.net - Complaints to news@netfront.net --
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...

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.