
The review of Alexander Nasonov's Promotion Traits start today. Since it's a small contribution it will be fast-track reviewed and the end of the review period is scheduled for April 6. Download URL ============ http://cpp-experiment.sourceforge.net/promote-20050917.tar.gz About the submission ==================== The Promotion Traits extend Boost.TypeTraits with templates that compute the type after promotion has been applied. Example: // given template<typename T> struct some_algorithm; template<> struct some_algorithm<int> { [...] }; // [...] more specializations // , [...] some_algorithm< typename integral_promotion<T>::type > [...] // makes some_algorithm work for any type T that promotes to an integer // (that is enums and smaller integral types) without the need for // additional specialization Review questions ================ Please always explicitly state in your review, whether you think the library should be accepted into Boost. You might want to comment on the following questions: - What is your evaluation of the design? - What is your evaluation of the implementation? - What is your evaluation of the documentation? - What is your evaluation of the potential usefulness of the library? - Did you try to use the library? With what compiler? Did you have any problems? - How much effort did you put into your evaluation? A glance? A quick reading? In-depth study? - Are you knowledgeable about the problem domain? Regards, Tobias (Review Manager)

Tobias Schwinger wrote:
The review of Alexander Nasonov's Promotion Traits start today. Since it's a small contribution it will be fast-track reviewed and the end of the review period is scheduled for April 6.
Download URL ============
http://cpp-experiment.sourceforge.net/promote-20050917.tar.gz
Do you have a link for those of us in the Windows realm? Thanks, Jeff

Jeff Flinn wrote:
Tobias Schwinger wrote:
The review of Alexander Nasonov's Promotion Traits start today. Since it's a small contribution it will be fast-track reviewed and the end of the review period is scheduled for April 6.
Download URL ============
http://cpp-experiment.sourceforge.net/promote-20050917.tar.gz
Do you have a link for those of us in the Windows realm?
The converted archive (ZIP format) has been placed into the vault: http://tinyurl.com/mcs7f Regards, Tobias (Review Manager)

Tobias Schwinger wrote:
Jeff Flinn wrote:
Tobias Schwinger wrote:
The review of Alexander Nasonov's Promotion Traits start today. Since it's a small contribution it will be fast-track reviewed and the end of the review period is scheduled for April 6.
Download URL ============
http://cpp-experiment.sourceforge.net/promote-20050917.tar.gz
Do you have a link for those of us in the Windows realm?
The converted archive (ZIP format) has been placed into the vault:
Regards, Tobias
Thanks, got it. Jeff

"Jeff Flinn" <TriumphSprint2000@hotmail.com> writes:
Tobias Schwinger wrote:
The review of Alexander Nasonov's Promotion Traits start today. Since it's a small contribution it will be fast-track reviewed and the end of the review period is scheduled for April 6.
Download URL ============
http://cpp-experiment.sourceforge.net/promote-20050917.tar.gz
Do you have a link for those of us in the Windows realm?
http://www.7-zip.org/ ;-) -- Dave Abrahams Boost Consulting www.boost-consulting.com

David Abrahams wrote:
"Jeff Flinn" <TriumphSprint2000@hotmail.com> writes:
Tobias Schwinger wrote:
The review of Alexander Nasonov's Promotion Traits start today. Since it's a small contribution it will be fast-track reviewed and the end of the review period is scheduled for April 6.
Download URL ============
http://cpp-experiment.sourceforge.net/promote-20050917.tar.gz
Do you have a link for those of us in the Windows realm?
I don't know how you keep on top of all of these things! :-) Thanks, Jeff

Hi, I'm interested to know in what situations the promotion_traits libarary is meant to be used? I looked at the standard and I see that it seems to follow that, but in practise the only similar situation of needing to know promotion rules in my own code was in choosing the type that the input types are to be converted to in some operation. The signature would then be simply promotion_traits<Lhs,Rhs>::type. I see that a one parameter version is necessary for completeness, but this could be solved by providing a defaul bool parameter. However the functionality I needed is provided by Boost.Typeof which might also cover the functionality this library provides anyway ? I am surprised to see that input parameters unrelated to promotion are allowed to pass unchanged to the output.The example given is e.g Expression ---> Result floating_point_promotion<int const>::type ---> int const I would expect, rather, to have a compilation failure in case of an invalid parameter? regards Andy Little

Andy Little wrote:
Hi,
I'm interested to know in what situations the promotion_traits libarary is meant to be used? I looked at the standard and I see that it seems to follow that, but in practise the only similar situation of needing to know promotion rules in my own code was in choosing the type that the input types are to be converted to in some operation.
Are you talking about _usual arithmetic conversions_? I like fine granular model. Since usual arithmetic conversions depend on integral promotion, it's logical to implement integral_promotion fisrt. BTW, LibrariesUnderConstruction has a reference to types_promotion_traits developed by Aleksey Gurtovoy. http://tinyurl.com/4kvla Is arithmetic_conversions_traits<> defined there what you need?
I am surprised to see that input parameters unrelated to promotion are allowed to pass unchanged to the output.The example given is e.g
Expression ---> Result floating_point_promotion<int const>::type ---> int const
I would expect, rather, to have a compilation failure in case of an invalid parameter?
I prefer promote-if-possible because it follows a semantic in the standard. For example, integral promotions can be applied when passing an argument to printf-like function. If integral promotions can't be applied to the argument, nothing happens. If you want to check whether promotion has an effect you can write is_same< T, promote<T>::type >::value. -- Alexander Nasonov

"Alexander Nasonov" wrote
Andy Little wrote:
Hi,
I'm interested to know in what situations the promotion_traits libarary is meant to be used? I looked at the standard and I see that it seems to follow that, but in practise the only similar situation of needing to know promotion rules in my own code was in choosing the type that the input types are to be converted to in some operation.
Are you talking about _usual arithmetic conversions_?
I am talking about usefulness. In what practical situation is promotion_traits likely to be used? Put it another way. What is the rationale for promotion_traits?
I like fine granular model. Since usual arithmetic conversions depend on integral promotion, it's logical to implement integral_promotion fisrt.
BTW, LibrariesUnderConstruction has a reference to types_promotion_traits developed by Aleksey Gurtovoy. http://tinyurl.com/4kvla Is arithmetic_conversions_traits<> defined there what you need?
IMO All this has recently been superceded by Boost.Typeof.
I am surprised to see that input parameters unrelated to promotion are allowed to pass unchanged to the output.The example given is e.g
Expression ---> Result floating_point_promotion<int const>::type ---> int const
I would expect, rather, to have a compilation failure in case of an invalid parameter?
I prefer promote-if-possible because it follows a semantic in the standard. For example, integral promotions can be applied when passing an argument to printf-like function. If integral promotions can't be applied to the argument, nothing happens.
If you want to check whether promotion has an effect you can write is_same< T, promote<T>::type >::value.
It might help to show useage examples to decide the behaviour, but is it not generally better to constrain a functions input to only those types for which its functionality is meaningful? If you want to widen the behaviour to accept other types you can use mpl::eval_if for example. regards Andy Little

Andy Little wrote:
I am talking about usefulness. In what practical situation is promotion_traits likely to be used? Put it another way. What is the rationale for promotion_traits?
1. to reduce number of instantiations in template code. For example: enum bits { bit1 = 1, bit2 = 2 }; lexical_cast<double>(bit1); lexical_cast<double>(bit1|bit2); produces 2 instantiantions of lexical_cast and 2 instantiantions of detail::lexical_stream. In general, this number is proportional to a number of enums used. If lexical_cast were to apply integral_promotion, this could reduce number of instantiantions of lexical_stream to one. 2. to find a type that can hold all values of enum type. This technique can be used in langbinding to make sure that all C++ enum values are mapped without truncation. 3. to use in other metafunctions like arithmetic_convertion_traits and to provide a solution for (_1 | _2)(bit1, bit2) lambda expression.
IMO All this has recently been superceded by Boost.Typeof.
Only native mode of Boost.Typeof can compete with hand-made integral_promotion or arithmetic_convertion_traits. Emulation is too complex and require registration of every enum type. Even in native mode you would need more then typeof(+T()) simply because this expression is not valid for some types. You should write is_subject_to_integral_promotion<T> metafunction and use eval_if.
It might help to show useage examples to decide the behaviour, but is it not generally better to constrain a functions input to only those types for which its functionality is meaningful? If you want to widen the behaviour to accept other types you can use mpl::eval_if for example. I knew this :) but I decided that writing eval_if< is_subject_to_integral_promotion<T>, ... > is not worth it. Existing behavior is better in all use-cases listed above. -- Alexander Nasonov

"Tobias Schwinger" wrote:
The review of Alexander Nasonov's Promotion Traits start today. http://cpp-experiment.sourceforge.net/promote-20050917.tar.gz
Bellow are few notes from me. I do not vote here as I am not that much knowledgeable of metaprogramming. /Pavel 1. The documentation should really start with Rationale section and should contain complete examples. Examples written in this thread would be good start. 2. Includes should use #include <boost/config.hpp> notation rather than #include "boost/config.hpp" 3. I got problems with Windows Intel 9.0: compiling... promote_enum_test.cpp icl: warning: problem with Microsoft compilation of 'P:\promote-20050917\libs\type_traits\test\promote_enum_test.cpp' P:\promote-20050917\libs\type_traits\test\promote_util.hpp(30): error: incomplete type is not allowed BOOST_STATIC_ASSERT(( ::boost::is_same< promoted , Promoted
::value )); ^ detected during instantiation of "void test<T,Promoted>() [with T=UIntEnum, Promoted=unsigned int]" P:\promote-20050917\libs\type_traits\test\promote_util.hpp(31): error: incomplete type is not allowed BOOST_STATIC_ASSERT(( ::boost::is_same< promoted_c , Promoted const ::value )); ^ detected during instantiation of "void test<T,Promoted>() [with T=UIntEnum, Promoted=unsigned int]" P:\promote-20050917\libs\type_traits\test\promote_util.hpp(32): error: incomplete type is not allowed BOOST_STATIC_ASSERT(( ::boost::is_same< promoted_v , Promoted volatile >::value )); ^ detected during instantiation of "void test<T,Promoted>() [with T=UIntEnum, Promoted=unsigned int]" P:\promote-20050917\libs\type_traits\test\promote_util.hpp(33): error: incomplete type is not allowed BOOST_STATIC_ASSERT(( ::boost::is_same< promoted_cv, Promoted const volatile >::value )); ^ detected during instantiation of "void test<T,Promoted>() [with T=UIntEnum, Promoted=unsigned int]" compilation aborted for P:\promote-20050917\libs\type_traits\test\promote_enum_test.cpp (code 2) Error executing cl.exe.
------------ promote_extentions_test.cpp icl: warning: problem with Microsoft compilation of 'P:\promote-20050917\libs\type_traits\test\promote_extentions_test.cpp' P:\promote-20050917\libs\type_traits\test\promote_extentions_test.cpp(23): error: enumeration value is out of "int" range LongLongEnum2_value = boost::integer_traits<boost::long_long_type>::const_max ^ [ snip many similar ] P:\promote-20050917\libs\type_traits\test\promote_util.hpp(30): error: incomplete type is not allowed BOOST_STATIC_ASSERT(( ::boost::is_same< promoted , Promoted
::value )); ^ detected during instantiation of "void test<T,Promoted>() [with T=LongLongEnum1,
Promoted=boost::long_long_type={__int64}]" [ snip many similar ] 4. Intel 7.0 seems to be right out, I was not able to compile any example. 5. Playing with BCB: I got some promising success but full port would require longer work. I can help here if it gets accepted into Boost. As an appetizer: all [::boost::] need to be converted into [boost::] (BCB doesn't like the leading ::) and there are some strange issues with namespaces; it feels that namespace boost { namespace type_traits { namespace detail { BOOST_TT_AUX_BOOL_TRAIT_DEF1(need_promotion, T, boost::is_enum<T>::value) ... put the macro generated code into wrong namespace. 6. In #if (defined(BOOST_MSVC) && (BOOST_MSVC == 1200)) \ || (defined(BOOST_INTEL_CXX_VERSION) && defined(_MSC_VER) && (BOOST_INTEL_CXX_VERSION <= 600)) \ || (defined(__BORLANDC__) && (__BORLANDC__ == 0x600) && (_MSC_VER == 1200)) just all versions of BCB should be covered. 5.5, 5.6 and 5.8 do have the __intX thing. BCB version 0x600 doesn't exist yet. Similarly all Windows Intel compilers I know about have __intX as a separate type - the check <= 600 should be omitted too. EOF

Pavel Vozenilek wrote:
1. The documentation should really start with Rationale section and should contain complete examples. Examples written in this thread would be good start.
Since it is a small addition to type_traits I decided to follow type_traits style. Rather then writing complete documentation I wrote small pieces that can be easily integrated into type_traits documentation.
2. Includes should use
#include <boost/config.hpp> Noted.
3. I got problems with Windows Intel 9.0:
Looks like it compiles in MS compatibility mode. I noticed some problems with MS compiler. Have you tried MSVC or Intel with MS compatibility switched off? There is a status for some compilers at the begginning of promote_enum_test.cpp: // Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for // 80x86 // /Ze (enable extentions) promotes UIntEnum incorrectly to int. // /Za (disable extentions) is totally broken. I was suprised to see that many compilers have problems with enums.
4. Intel 7.0 seems to be right out, I was not able to compile any example.
I tested only Intel 8.1 for Linux on FreeBSD. It works fine.
5. Playing with BCB: I got some promising success but full port would require longer work. I can help here if it gets accepted into Boost.
I appreciate this.
As an appetizer: all [::boost::] need to be converted into [boost::] (BCB doesn't like the leading ::) and there are some strange issues with namespaces; Thanks.
6. In
#if (defined(BOOST_MSVC) && (BOOST_MSVC == 1200)) \ || (defined(BOOST_INTEL_CXX_VERSION) && defined(_MSC_VER) && (BOOST_INTEL_CXX_VERSION <= 600)) \ || (defined(__BORLANDC__) && (__BORLANDC__ == 0x600) && (_MSC_VER == 1200))
just all versions of BCB should be covered. 5.5, 5.6 and 5.8 do have the __intX thing.
BCB version 0x600 doesn't exist yet.
Similarly all Windows Intel compilers I know about have __intX as a separate type - the check <= 600 should be omitted too.
I copied this #if from <boost/type_traits/is_integral.hpp> Have you noticed TODO nearby? It says: // TODO: common macro for this #if. Or better yet, PP SEQ of non-standard types. Thanks for comments, -- Alexander Nasonov

Tobias Schwinger wrote:
- What is your evaluation of the design?
I wonder if the three functions are necessary together? Either there should only be promote or there should only be integral_promotion, float_promotion. The main rationale for integral_promotion is for enums. float promotion and promotion usage are already handled by Boost.Typeof. ints and floats are very different entities and I wonder if its approporiate to apply the same behaviours. An example of the difference is the boost::integral_constant<T,Tvalue>, where the type is naturally constrained to be an int or enum but floats arent valid. I dont really like the fact types unrelated to int or floats can silently pass through as a general rule, but I think I see the reasoning given the use cases. It could be documented though.
- What is your evaluation of the implementation?
I havent looked at the implementation.
- What is your evaluation of the documentation?
I think it needs some more rationale and examples. I understand its meant to fit with type_traits, but the documentation for other type_traits does include examples and there is room for a bit of rationale too.
- What is your evaluation of the potential usefulness of the library?
The main use seems to be limited to enums. If the type of promotion_traits can determine the number of bits an enum requires to be stored in then that is useful. That seems to be a feature unique to this library, but I havent tested it out to see if it works as it failed in VC7.1
- Did you try to use the library? With what compiler?
Tried <libs/type_traits/promote_enum_test.cpp> in VC7_1 and gcc4.0. succeeded in gcc4.0
Did you have any problems?
<libs/type_traits/promote_enum_test.cpp> Failed in VC7.1 (Extensions disabled)
- How much effort did you put into your evaluation? A glance? A quick reading? In-depth study?
A quick reading.
- Are you knowledgeable about the problem domain?
Yes.
Please always explicitly state in your review, whether you think the library should be accepted into Boost.
I vote yes to accept it. regards Andy Little

Andy Little <andy <at> servocomm.freeserve.co.uk> writes:
I wonder if the three functions are necessary together?
Either there should only be promote or there should only be integral_promotion, float_promotion.
I was never sure about floating_point_promotion<> and promote<>. Section 13.3.3.1.1 of the standard conviced me to add them. It defines Promotion category of standard conversion sequences.
The main rationale for integral_promotion is for enums. float promotion and promotion usage are already handled by Boost.Typeof.
I would say, floating_point_promotion<> is easily implementable even without Boost.Typeof.
ints and floats are very different entities and I wonder if its approporiate to apply the same behaviours.
I agree.
I dont really like the fact types unrelated to int or floats can silently pass through as a general rule, but I think I see the reasoning given the use cases. It could be documented though.
It's documented by not emphasized: type: T if integral promotion can't be applied to an rvalue of type T; otherwise, a type of integral promotion of an rvalue of type T. Resulting type is same cv-qualified as T.
I think it needs some more rationale and examples. I understand its meant to fit with type_traits, but the documentation for other type_traits does include examples and there is room for a bit of rationale too.
Only few type_traits classes are explained in tutorial. I can't add mine without asking the authors.
I vote yes to accept it.
Thanks. -- Alexander Nasonov
participants (6)
-
Alexander Nasonov
-
Andy Little
-
David Abrahams
-
Jeff Flinn
-
Pavel Vozenilek
-
Tobias Schwinger