Boost logo

Boost :

Subject: Re: [boost] [Concepts] Definition. Was [GSoC] [Boost.Hana] Formal review request
From: Paul A. Bristow (pbristow_at_[hidden])
Date: 2014-08-14 08:06:46


> -----Original Message-----
> From: Boost [mailto:boost-bounces_at_[hidden]] On Behalf Of Niall Douglas
> Sent: 14 August 2014 12:36
> To: boost_at_[hidden]
> Subject: Re: [boost] [Concepts] Definition. Was [GSoC] [Boost.Hana] Formal
review
> request

> > 2. Unless there are reasons to do otherwise, such library should
> > attempt to issue a diagnostic message during compilation that the
> > requirements on types have not been satisfied. This doesn't need to be
> > Boost.ConceptCheck (if no consensus can be reached on using it).
> > Probably a static assert with a type trait should be enough:
> >
> > template<class T>
> > quick_sort(iterator<T> begin, iterator<T> end) {
> > static_assert(is_less_than_comparable<T>::value, "T is not
> > LessThanComparable");
> > static_assert(is_swappable<T>::value, "T is not Swappable");
> > // do the work
> > }
> >
> > Not an ideal, but perhaps less controversial.
>
> The above is what I do in my own code - indeed, just last night I wrote this
for my
> concurrent_unordered_map:
>
> /*! \brief Factory function for many node_ptr_types, optionally using an
array of
> preexisting
> memory allocations which must be deallocatable by this container's
allocator.
> */
> template<class InputIterator> std::vector<node_ptr_type>
node_ptrs(InputIterator
> start, InputIterator finish, value_type
> **to_use=nullptr)
> {
> static_assert(std::is_same<typename std::decay<typename
> InputIterator::value_type, value_type>::value>::type, "InputIterator type is
not my
> value_type");

At the same time as doing this, you could easily also add something like

  \tparam InputIterator InputIterator A type that must match value_type. This
can include user-helpful examples and other info (does it have to be a built-in
type say).

and this would show up in any automatically generated reference documentation
system, for example Doxygen (along with your description " Factory function for
many node_ptr_types").

<big snip>

Paul

---
Paul A. Bristow
Prizet Farmhouse
Kendal UK LA8 8AB
+44 (0) 1539 561830

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