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

Detecting the arity of a constructor at compile time


I was wondering if it is at all possible to detect the arity of
constructors at compile time using some combination of macros and
template metaprogramming. I'd like to be able to determine whether
a class has, for instance, a constructor with two arguments or a
constructor with three arguments. Is there any way to do this?

Michael
Aug 4 '06 #1
3 1499
Michael Feathers wrote:
I was wondering if it is at all possible to detect the arity of
constructors at compile time using some combination of macros and
template metaprogramming. I'd like to be able to determine whether
a class has, for instance, a constructor with two arguments or a
constructor with three arguments. Is there any way to do this?
I'd like to educate myself in this matter. Could you explain why you
want to do that?

Many thanks!

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 4 '06 #2
Victor Bazarov wrote:
Michael Feathers wrote:
>>I was wondering if it is at all possible to detect the arity of
constructors at compile time using some combination of macros and
template metaprogramming. I'd like to be able to determine whether
a class has, for instance, a constructor with two arguments or a
constructor with three arguments. Is there any way to do this?


I'd like to educate myself in this matter. Could you explain why you
want to do that?

Many thanks!

V

I'd like to write a dependency injection framework that doesn't place
many constraints on the types it manages. I suspect that it would
be easier to use setter-based injection and something like
Alexandrescu's GenLinearHierarchy, but I was wondering if there is
a way to do constructor injection.

Michael Feathers
www.objectmentor.com

Aug 4 '06 #3
On Fri, 04 Aug 2006 13:43:14 GMT, Michael Feathers
<mf*******@objectmentor.comwrote:
>I'd like to write a dependency injection framework that doesn't place
many constraints on the types it manages. I suspect that it would
be easier to use setter-based injection and something like
Alexandrescu's GenLinearHierarchy, but I was wondering if there is
a way to do constructor injection.
In Java DI is usually implemented with interfaces. You do them same in
C++ with abstract base classes. WRT the 'arity of constructors' have
you considered default arguments?

Best regards,
Roland Pibinger
Aug 4 '06 #4

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

Similar topics

18
by: Matt | last post by:
I try to compare the default constructor in Java and C++. In C++, a default constructor has one of the two meansings 1) a constructor has ZERO parameter Student() { //etc... } 2) a...
21
by: Steve - DND | last post by:
I know it's possible to require inheriting classes to implement a particular function or property, but is it possible to require a inheriting class to implement a constructor of it's own? ...
19
by: Martin Oddman | last post by:
Hi, I have a compiling problem. Please take a look at the code below. I have an application that is built upon three tiers: one data tier (Foo.DataManager), one business tier (Foo.Kernel) and...
45
by: Ben Blank | last post by:
I'm writing a family of classes which all inherit most of their methods and code (including constructors) from a single base class. When attempting to instance one of the derived classes using...
12
by: Andrew Schepler | last post by:
When compiled with Visual C++ .NET 2003 (only), the program below aborts as though no matching catch clause is present. If the copy constructor of A is made public, it successfully catches the...
5
by: Z.K. | last post by:
In C#, using the StreamReader, how do I detect when you get to the end of line. I am reading a text file using the Read() function and I need to detect the \n\r, but everything I try does not...
4
by: Howard Gardner | last post by:
// I think that there is no way to write the template "cant_write_me" in // this example. Would love to be wrong. // one of many approaches that won't work template< template< typename class...
1
by: Bart Simpson | last post by:
Can anyone explain the concept of "slicing" with respect to the "virtual constructor" idiom as explain at parashift ? From parashift: class Shape { public: virtual ~Shape() { } ...
12
by: Rahul | last post by:
Hi Everyone, I have the following code and i'm able to invoke the destructor explicitly but not the constructor. and i get a compile time error when i invoke the constructor, why is this so? ...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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...
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...

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.