473,771 Members | 2,406 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_protoc ols" which take two protocols of above
mentioned protocol types

template<typena me P0, typename P1>
connect_protoco ls(P0& p0, P1 & p1)
{..}
What is requires in the body of "connect_protoc ols" 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 3965
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_protoc ols" which take two protocols of above
mentioned protocol types

template<typena me P0, typename P1>
connect_protoco ls(P0& p0, P1 & p1)
{..}
You forgot to state the return type of the function.
What is requires in the body of "connect_protoc ols" 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<typena me P0, typename P1>
void connect_protoco ls(P0& p0, P1 & p1)
{
create(p0, p1);
}

Jul 27 '05 #2
>
What is requires in the body of "connect_protoc ols" 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_protoco ls(T &First, T &Second);

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

template<>
void connect_protoco ls(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
3132
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 absolute address of alpha to access to it. What confuses me is that when the variable is dynamically allocated, how does the compiler implement it? We know the address of the variable until run-time. During the compilation, how can we access to the...
4
11203
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
7587
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 dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
3
6039
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 sheet 1 to sheets 2,3,4 and 5. Can you see anything wrong. Help much appreciated. Thanks Sub Macro1()
10
1355
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
1491
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 time to compile all projects.
11
2019
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 the same exact sorting counts also..shouldn't they differ somewhat? Source and data file below. Thanks
12
2767
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
5607
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
9619
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10103
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9911
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7460
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.