Opened 12 years ago

Closed 12 years ago

#4296 closed Feature Requests (fixed)

has_iterator, has_const_iterator metafunctions

Reported by: Tomas Puverle (tomas dot puverle at morganstanley dot com) Owned by: Neil Groves
Milestone: Boost 1.46.0 Component: range
Version: Boost 1.44.0 Severity: Not Applicable
Keywords: has_iterator, has_const_iterator Cc:

Description

This function is useful when using enable_if/disable_if for distinguishing between plain types and ranges of types.

Ideally, this would be added as an include to boost/range/metafunctions.hpp.

Code and test case attached. Tested against boost 1.43.0 with MSVC and gcc 4.2.

Attachments (1)

boost.range.zip (4.4 KB ) - added by tomas.puverle@… 12 years ago.
A patch for boost range with two new metafunctions and a test case.

Download all attachments as: .zip

Change History (4)

by tomas.puverle@…, 12 years ago

Attachment: boost.range.zip added

A patch for boost range with two new metafunctions and a test case.

comment:1 by Steven Watanabe, 12 years ago

This would be better implemented as

BOOST_MPL_HAS_XXX_TRAIT_DEF(type);
template<class T>
struct has_iterator : has_type<boost::range_iterator<T> > {};
template<class T>
struct has_const_iterator : has_type<boost::range_const_iterator<T> > {};

comment:2 by Neil Groves, 12 years ago

Status: newassigned

comment:3 by Neil Groves, 12 years ago

Milestone: Boost 1.44.0Boost 1.46.0
Resolution: fixed
Status: assignedclosed

I have implemented a solution based primarily on stevens suggestion since using BOOST_MPL_HAS_XX_TRAIT_DEF improves compiler support.

I have chosen to implement this using enable_if to select a base class since this works better on many compilers (due to the base class being dependent on the template parameters) than the snippet posted above.

Note: See TracTickets for help on using tickets.