Boost logo

Boost :

From: Gennadiy Rozental (gennadiy.rozental_at_[hidden])
Date: 2004-01-04 01:44:20


Hi,

I know that numeric conversion library review is over and it's got accepted.
But since I was on vocation at the time let me give these comments now to
the version that was submitted. I did not have time to look through review
comments, so there may be repetitions.

Design
------------------------------------------------------------------

In most part proposed design looks reasonable. I have only one major IMO
concern.

Issue: (Major) Why traits are template parameter of converter?
 I've expressed my opinion in the matter before: Traits - as name suggest
could not be policy. IOW should not be template parameters. Traits are type
specific and an ability to supply them independently to the primary type in
most cases leads to invalid/too complicated design.
   Traits are not only template parameters of public converter class but
many other classes. IMO all of them should use S and T as template
parameters instead.

1. Why bounds<>::smallest() returns 0 and not 1, for integral types? Doesn't
it supposed to return smallest positive value?

2. boost::numeric::converter is part of public interface and have 7 (should
be 6) template parameters. Such number of parameters asks for named template
parameters facility.

3. All converter policies required to be stateless. Why?
   I don't understand this requirement. Moreover, I believe in some (rare)
cases I may want statefull one. For example Let say I want to keep track of
location where risky arithmetic operations performed. So OverflowHandler
needs hold on to this position and report it in exception.

4. converter<>::convert converts only rvalue. Why?
  IMO we need second operation that works with lvalues. What if I want to
convert int& into char&?

5. IMO Thee should be simple direct way to make range checking debug only
operation

Implementation
------------------------------------------------------------------

1. I am not sure that it is really the issue. But if it is it would be major
concern. Whole implementation is based on the following logic

template<...>
some_type_generator
{
     typedef some-complex-type-generator case1;
     typedef some-complex-type-generator case2;
     ....

    typedef ct_switch( type_selector ) case1 or case2 .... type;

// for example
// typedef typename
//
mpl::apply_if<use_internal_RC,InternalRangeCheckerQ,UserRangeCheckerQ>::type
// RangeChecker ;
};

I wonder whether all caseN types get instantiated. If yes, it may be quite
wasteful.

2. Could you please explain logic behind subranged_Unsig2Sig,
subranged_Udt2BuiltIn, subranged_BuiltIn2Udt implementations
3. ct_switch4 implementation: could we make this implementation more
efficient? If is_case0 is true why would we need the rest checks?
4. How would trivial_converter_impl will work if one convert from const int
to int? Should it work?
5. Separation of policies in make_converter_from type generator looks
unclear tome. In an case: why would I want to use it, instead of using
converter directly? NTP looks better solution to me.

Docs
------------------------------------------------------------------

Definitions:

1. Why "object representation" is sequence of bytes, while "value
representation" is set of bits?
2. "Typed value" definition: how it could by determined only by set of bits
(value representation)? What about signed unsigned values? They have the
same value representation as a set of bits.
3. "intrinsic value" definition: why are you using unsigned characters
instead of bytes here?
4. After "abstraction" definition: "Abstraction is just an abstract
operation" - it's like saying salt is salty
5. In C++ arithmetic types section: operation {} needs to be defined
6. In C++ arithmetic types section: " The integer types are required ....
" - what does this statement mean
7. In C++ arithmetic types section: you give some advice at the end - does
it belong here?
   Actually I completely disagree with second part of what you recommend.
IMO one should use unsigned values to model non-negative values. For once
it's better reflect design. And also it's more safe and efficient. Would I
use signed value as an container index, then before accessing value by index
I need to not only check that it does not exceed size of the container but
also check that it is non negative - twice as much work and easy to forget.
Also in most cases errors with "negative" index are easier to catch.
Instead of more or less safe (begin-1) memory access, one would get (begin +
max_int)
8. In numeric types section: definitions for integer and floating types are
unclear to me. Does everybody know what whole and real means?
9. In Range and Precision: "The set of representable values of type 'T'. is
...." - representable where?
10. Why precision is defined the way it is defined? What value this
definition brings? There seems to be two different concepts combined undef
the same hood.
11. Exact, ... section: " Notice that a representation is an operation ...
". Actually "Rounding" is an operation, which has direction and error. This
name seems more logical. So we are getting representation my means of
applying rounding operation to an abstract value.
12. In "Standard (numeric) Conversions": "Promotions, both Integral and ...
is not changed with the conversion" - should be promotion?
13. In "Standard (numeric) Conversions": what does "in a sequel" mean?
14. In "Standard (numeric) Conversions": "Floating to Floating conversions
are defined only if 'N' is representable" - where?
15. In "Subranged Conversion ... ": why are you using word intersection in
one place and symbol & in another?
16. In "Subranged Conversion ... ": "Notice that for S->T, the adjective
subranged applies to 'T'" - why not to conversion?
17. Discussion list address is wrong

Type requirements and ....

18. ... in order to use the default Trunc<> policy - Instead of putting it
into brackets

Header boost/numeric/conversion_traits.hpp

19. In template class is_subranged description you use source (first letter
lowercase) and Target (first letter uppercase).

Header boost/numeric/converter.hpp

20. range_check_result used but not defined
21 "If the user supplied a UserRangeChecker policy, is this policy which
...". "is this" looks incorrect
22. "This function is externally supplied by the RawConverter policy
class.". "externally supplied" term is unclear.
23. "Internal Member Functions: ...., but they can be called separately for
specific needs.". If they could be called by end-user why do you name them
internal?

Header boost/numeric/converter_policies.hpp

24. "This stateless non-template policy class": what do you mean by
non-template? And later you mention template policy class. What do you mean
by that?

Code
------------------------------------------------------------------

1. Copyright needs to be updated.
2. Why do you name namespace convdetail/boundsdetail and not detail?
3. IMO for_both maybe named if_both
4. Why ct_switch4 and not ct_switch3. After all you have only 3 case clauses
5. for_round_style and similar selectors I would name select_round_style
e.t.c.
6. Why do you need get_ in get_is_subranged?
7. GetRC_Sig2Sig_or_Unsig2Unsig I would name GetRC_SameSig
8. Name you are using for some identifiers looks like mix of 2 styles (
GetRC_Sig2Unsig ). I think we may better following boost naming
recommendations (like get_rc_sig_2_unsig)
9. Why do you need first three typedefs in rounding converter
implementation?
10. Why do you need separate files for most of implementation details?
   Majority of implementation presented as one tiny header in numeric
directory that present public interface implemented by inheritance from
implementation located in separate header in details directory. I do not see
real advantage in such separation.
11. Why each enums are defined in separate header? Did you intend them to be
used separately from rest of implementation?

Tests
------------------------------------------------------------------

1. Why test_helpers are .cpp and not .hpp?
2. All your test ask to be written in terms of test cases. Do you need help
to convert them to use unit_test_framework?
3. Many of your tests ask to be converted to use new test case template
facility. I attached I test that I reworked in this direction. Do you need
help with that?

Congratulation to the author for the solid work. Hope my comments were
productive and may help to make it even better.

Regards,

Gennadiy.

begin 666 traits_test.zip
M4$L#!!0````(`!HC(C"/2\^#D_at_P``*!B```/`"0`=')A:71S7W1E<W0N8W!P
M"@`@```````!`!@`!,L/1A+1PP&]5[AIC=+#`;AIMCK\T,,!U5QK;]M&%OT>
M(/_AUOU0*:#MV 46"UDQX#IRUUB_$,D%]@6"(D?R;"D.,3.THP;][SM//D1*
MIB2:S*:(2\[CWC-G+L_E2,X]/H;>91]./W[\V8$K1",O"@C<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:?W! O
MI+#D/JXY'PP"/!>-)Q^MU.MBFRDB=?W)Y&'UL(T?KR>C'AS<::OY*L9&Z.24
M`_/TE;9'<G-R,K1I9[6H6.%#7 =*Q0.*'W-6_-._at_E=\+MW[,KQC:KR4+WU&:
MS\GM!SDZ5%@)?B%>U1 5,2R-25OSG16(/#SW_at_J!G&#2:=?MP<S$9;1(O)V?.
M?!.M35+$$QJI7JN)_P-02P$"&0`4````" `:(R(PCTO/@Y(,``"@8@``#P``
M`````````" `````````=')A:71S7W1E<W0N8W!P4$L%!@`````!``$`/0``
'`.,,````````
`
end


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk