Boost logo

Boost :

From: Rob Stewart (stewart_at_[hidden])
Date: 2004-05-24 16:29:46


From: christopher diggins <cdiggins_at_[hidden]>
>
> template
> <
> class constraints_policy,
              ^^^^^^^^^^^^^^^^^^
I think the usual naming convention would make that
"Constraints" or something similar.

> bool implicit_conversion_policy = true
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
ditto: "ImplicitConversion"

> >
> class constrained_value {
> private:
> struct unused_struct { };

Why the "_struct" suffix? Wouldn't "unused" suffice?

> public:
> typedef constrained_value<constraints_policy,
> implicit_conversion_policy> self;
> typedef typename constraints_policy::value value;
> typedef typename mpl::if_c<implicit_conversion_policy, value,
> unused_struct>::type value_parameter;

          typedef Constraints constraints_policy;
          typedef ImplicitConversion conversion_policy;

> static constraints_policy get_constraints() { return
> constraints_policy(); }
> constrained_value() { }
> constrained_value(const self& x) { assign(x.get_value()); }
> constrained_value(value_parameter x) { assign(x); }

What if the type is not a built-in? That is, what if copying is
expensive? Use TypeTraits to determine whether to pass by value
or by reference.

> const value get_value() const { return m; }
> operator value() { return m; }

Why return by value? Why not const reference? Even better, use
TypeTraits to determine whether to return by value or by
reference.

> self& operator=(const self& x) { assign(x.get_value()); return
> *this; }
> self& operator=(value_parameter x) { assign(x); return *this; }

Use TypeTraits here, too.

> void assign(unused_struct x) { }
> void assign(value_parameter x) { constraints_policy::assign(x, m); }

And here.

Also, it you've shown the arguments in the reverse order from
what I'd expect. The assignment operator puts the destination on
the left, so I'd expect m on the left.

> private:
> value m;
> };

-- 
Rob Stewart                           stewart_at_[hidden]
Software Engineer                     http://www.sig.com
Susquehanna International Group, LLP  using std::disclaimer;

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