Boost logo

Boost :

From: Doug Gregor (gregod_at_[hidden])
Date: 2001-03-27 13:30:14

On Monday 26 March 2001 11:28, you wrote:
> on 3/25/01 7:20 PM, Jens Maurer at Jens.Maurer_at_[hidden] wrote:
> > I've had a look at crc version 9 from the boost files section.
> >
> > Here are a few comments:
> >
> > boost/crc.hpp
> >
> > - The exact_uint_t<> template is once declared and only later defined.
> > That makes for a lot of repeated #ifdef and, as an implementation detail,
> > doesn't buy much clarity either. Could we omit the declarations?
> Is it OK to define template specializations without declaring them,
> especially if you only have a forward declaration for the general version?

Yes, it is. It is often used when there are requirements on the template
parameters that can be checked with (partial) specialization. Failure to meet
the requirements results in an attempt to instantiate an undefined type. For

template<typename Vector> struct require_vector;

template<typename T, typename Allocator>
struct require_vector< std::vector<T, Allocator> > {};

The technique

  std::size_t Bits,
  unsigned long TruncPoly = 0ul,
  typename Implementation =
    typename get_implementation_tag<Bits, TruncPoly, ...>::type
struct crc;

template< std::size_t Bits, unsigned long TruncPoly, ...>
struct crc<Bits, TruncPoly, ..., crc_fast_tag>
  // the fast implementation

The benefits of this type of generative approach are:
        1) No '::type' to confuse users
        2) You can specialize based on "crc". With typical '::type' generative
interfaces, you don't know what the returned type will be, so you can't
possibly specialize for any CRC computation class. This could get really bad
when you use multiple generic libraries that use generative interfaces and
happen to have free functions of the same name.


Boost list run by bdawes at, gregod at, cpdaniel at, john at