Any constructor evaluation in compile time?
Hi everyone, I am new at the excellent Boost library. It is an incredible source of smart techniques and ticks. I would like to ask if there is a way to evaluate, in compile time, the existence of a specific constructor, except from the constructor default and copy constructor (I know the functions has_trivial_constructor and has_trivial_copy from the type_traits library). For example in the following code, I would like to evaluate the existence of both "A(const Config& config)" and " template <class Random> A(const Config& config, Random& random) " constructors. Class A { A(){.} A(const Config& config){.} template <class Random> A(const Config& config, Random random){.} . } Also, I would like to know why and how the has_trivial_constructor works. Thank you in advance for your kindly help. All the best, Yutaka Leon Suematsu.
"Yutaka Leon Suematsu"
Hi everyone,
I am new at the excellent Boost library. It is an incredible source of smart techniques and ticks.
I would like to ask if there is a way to evaluate, in compile time, the existence of a specific constructor, except from the constructor default and copy constructor (I know the functions has_trivial_constructor and has_trivial_copy from the type_traits library). For example in the following code, I would like to evaluate the existence of both "A(const Config& config)"
You can do something like this with is_convertible
and " template <class Random> A(const Config& config, Random& random) " constructors.
This one there's no known technique for.
Class A { A(){.} A(const Config& config){.} template <class Random> A(const Config& config, Random random){.} . }
Also, I would like to know why and how the has_trivial_constructor works.
When it works, it relies on implementation-specific magic help from the compiler. -- Dave Abrahams Boost Consulting www.boost-consulting.com
I sometimes need to make approximate string matching, i.e. to know whether to strings are close, without being identical. There are methods to do that, see "Approximate String Matching", Levenshtein's algorithm for strings distance, ASM, Ukkonen, Boyer-Moore algorithms, etc... I would like to know if there is a plan to provide this kind of feature in Boost, maybe with the regular expression library or the string algorithms. Thanks !
remi.chateauneu@gmx.de wrote:
I sometimes need to make approximate string matching, i.e. to know whether to strings are close, without being identical. There are methods to do that, see "Approximate String Matching", Levenshtein's algorithm for strings distance, ASM, Ukkonen, Boyer-Moore algorithms, etc...
I would like to know if there is a plan to provide this kind of feature in Boost, maybe with the regular expression library or the string algorithms.
It sounds like this would go in the string algorithms library rather than regex. If no one is already working on it, it would be helpful for you to suggest possible interfaces for the algorithms you mention, or better yet, provide an implementation. BTW, this message appears to be a reply to a message in the "Any constructor evaluation..." thread, so some people may overlook it.
Thanks !
Jonathan
I would like to ask if there is a way to evaluate, in compile time, the existence of a specific constructor, except from the constructor default and copy constructor (I know the functions has_trivial_constructor and has_trivial_copy from the type_traits library). For example in the following code, I would like to evaluate the existence of both "A(const Config& config)"
You can do something like this with is_convertible
Thank you Dave, it works perfect. If the constructor takes one paramater it can be used , but in the case of two or more parameters?? Is it possible to evaluate, in compile time, the existence of a certain member function in a class? Thank you in advance, Yutaka Leon Suematsu
Yutaka Leon Suematsu wrote:
Is it possible to evaluate, in compile time, the existence of a certain member function in a class?
How about taking it's address (like "&class::member") ? I suppose you're talking about templates, so something like "&T::member" would be more appropriate. Carl
"Yutaka Leon Suematsu"
I would like to ask if there is a way to evaluate, in compile time, the existence of a specific constructor, except from the constructor default and copy constructor (I know the functions has_trivial_constructor and has_trivial_copy from the type_traits library). For example in the following code, I would like to evaluate the existence of both "A(const Config& config)"
You can do something like this with is_convertible
Thank you Dave, it works perfect.
If the constructor takes one paramater it can be used , but in the case of two or more parameters??
Your out of luck.
Is it possible to evaluate, in compile time, the existence of a certain member function in a class?
Yep. If you know both the name and exact signature, you use SFINAE with the member function pointer. -- Dave Abrahams Boost Consulting www.boost-consulting.com
David Abrahams wrote:
"Yutaka Leon Suematsu"
writes: Is it possible to evaluate, in compile time, the existence of a certain member function in a class?
Yep. If you know both the name and exact signature, you use SFINAE with the member function pointer.
Could you give or point us to an example, please? Thanks, Noel
Noel Yap
David Abrahams wrote:
"Yutaka Leon Suematsu"
writes: Is it possible to evaluate, in compile time, the existence of a certain member function in a class? Yep. If you know both the name and exact signature, you use SFINAE with the member function pointer.
Could you give or point us to an example, please?
There are a couple here: http://tinyurl.com/4g5ce -- Dave Abrahams Boost Consulting www.boost-consulting.com
Noel Yap wrote:
David Abrahams wrote:
"Yutaka Leon Suematsu"
writes: Is it possible to evaluate, in compile time, the existence of a certain member function in a class?
Yep. If you know both the name and exact signature, you use SFINAE with the member function pointer.
Could you give or point us to an example, please?
See the references cited here: http://lists.boost.org/MailArchives/boost/msg77454.php Jonathan
participants (6)
-
Carl Seleborg
-
David Abrahams
-
Jonathan Turkanis
-
Noel Yap
-
remi.chateauneu@gmx.de
-
Yutaka Leon Suematsu