Boost logo

Boost :

Subject: Re: [boost] [concept_check] addable
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-04-23 16:13:48


on Mon Apr 23 2012, lcaminiti <lorcaminiti-AT-gmail.com> wrote:

> Dave Abrahams wrote
>>
>> Actually it checks that there exists an operator+ from T non-const
>> lvalue x T non-const lvalue to U, where U is convertible to T const&
>>
>
> Got it. That works for me but I might change the T non-const lvalue to T
> const&. For curiosity, is there a way to program the concept ruling out the
> implicit conversion from U to T const&?

Sure; lots of ways. One would be to pass the result to a function like

      template <class T, class U>
      void same_type(U const&)
      {
           BOOST_MPL_ASSERT((is_same<T,U>));
      }

You can see another similar example in the first example at
http://www.boost.org/doc/libs/1_36_0/libs/concept_check/creating_concepts.htm

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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