Re: [boost] Re: how to avoid inclusions?
"Thorsten Ottosen" <[EMAIL PROTECTED]> writes: > my code does not include , or , but it does need > . > > Some of the functionality of the container_traits are shown here: > > > template< typename C > > bool is_container() > { > return boost::container_traits::is_container(); > } ... Yes, you can take an approach like this one, but it will cause false positives in some circumstances. If that's acceptable for your application, then it's a good answer. -- Dave Abrahams Boost Consulting www.boost-consulting.com ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[boost] Re: how to avoid inclusions?
Hereby at least a partial solution which so far works with gcc3.2 and comeau 4.3.0.1. The complete source can be found in the sandbox : boost-sandbox/libs/sequence_algo/test/container_traits.hpp boost-sandbox/boost/sequence_algo/container_traits.hpp my code does not include , or , but it does need . Some of the functionality of the container_traits are shown here: template< typename C > bool is_container() { return boost::container_traits::is_container(); } template< typename C > bool is_sequence() { return boost::container_traits::is_sequence(); } template< typename C > bool is_contiguous_sequence() { return boost::container_traits::is_contiguous_sequence(); } template< typename C > bool is_associative() { return boost::container_traits::is_associative(); } int main() { using namespace boost; using namespace std; typedef list list_t; typedef vector vector_t; typedef map map_t; assert( is_container() ); assert( is_sequence() ); assert( is_sequence() ); assert( !is_sequence() ); assert( is_contiguous_sequence() ); assert( !is_contiguous_sequence() ); assert( !is_contiguous_sequence() ); assert( is_associative() ); assert( !is_associative() ); assert( !is_associative() ); } -- The implementation uses SFINAE and relys on some assumptions that I'm not a 100% sure about. The core of the implementation is this: template< typename C > true_t is_container( const C&, const typename C::iterator& = typename C::iterator() ); template< typename T, std::size_t sz > true_t is_container( const T (&)[sz] ); false_t is_container( ... ); template< typename C > true_t is_associative_container( const C&, const typename C::key_type = typename C::key_type() ); false_t is_associative_container( ... ); template< typename C > struct tag_generator { static C& c; BOOST_STATIC_CONSTANT( bool, is_container_ = sizeof( true_t ) == sizeof( is_container( c ) ) ); BOOST_STATIC_CONSTANT( bool, is_associative_container_ = sizeof( true_t ) == sizeof( is_associative_container( c ) ) ); BOOST_STATIC_CONSTANT( bool, is_sequence_container_ = is_container_ && not is_associative_container_ ); enum { has_random_access_iterator_ = ::boost::is_same< std::random_access_iterator_tag, typename std::iterator_traits< typename container_traits::iterator > ::iterator_category >::value }; BOOST_STATIC_CONSTANT( bool, is_contiguous_sequence_container_ = ::boost::is_array::value || is_sequence_container_ && has_random_access_iterator_ ); }; Comments are more than welcome. regards Thorsten PS: How do you all use BOOST_STATIC_CONSTANT together with typetraits that takes two parameters? As you can see I had to fall back on an enum. ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Re: [boost] Re: how to avoid inclusions?
On Fri, Mar 07, 2003 at 08:09:35PM +0100, Gennaro Prota wrote: > On Fri, 7 Mar 2003 18:17:56 +0100, Pavol Droba <[EMAIL PROTECTED]> > wrote: > > >I wanted to do something else: > > > > template struct trait_class > > { > > > > } > > > > template struct trait_class > > > { > > > > } > > > >without #include > > > >Is this possible? > > > Practically speaking, no. At least not in a portable, conforming way. > You can (under certain limitations) provide specializations like > > > class A { }; > namespace std { template<> class numeric_limits {}; } > > > but you can't otherwise add declarations to std. There are several > reasons for this limitation. > > AFAIK the committee discussed the possibility to provide fwd versions > of standard headers other than but decided not to do so. > My question is then following: How do the boost libraries solve this problem? I see only 2 possibilities, both not very nice. - Silently include all stl container headers ( or at least meny of them ) - Divide the specialization into several files ( one for each container ) and ask the user to include the specific one. Is there some other option I don't know about? Pavol ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
Re: [boost] Re: how to avoid inclusions?
On Fri, Mar 07, 2003 at 04:54:14PM +, John Fletcher wrote: > > > Pavol Droba wrote: > > > I wanted to do something else: > > > > template struct trait_class > >{ > > > >} > > > >template struct trait_class > > >{ > > > >} > > > > without #include > > > > Is this possible? Or is there a way how to achieve the same efect, but without > > including ? > > > > I see, that is probably isn't .. > > > > Pavol > > Could you put each specialisation in a separate header file and arrange only to > include the ones which you > need, the vector one when you include etc? > I see this as the only possibility. It's not very nice though. This way user is required to include a header each time he want to use a container. It gets even more confusing, because the trait class is supposed to be only an implementation detail. However this way, users either accept the inclusion of unwanted headers, or they have to include specific header manualy. Typical now win solution :( ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[boost] Re: how to avoid inclusions?
On Fri, 7 Mar 2003 18:17:56 +0100, Pavol Droba <[EMAIL PROTECTED]> wrote: >I wanted to do something else: > > template struct trait_class > { > > } > > template struct trait_class > > { > > } > >without #include > >Is this possible? Practically speaking, no. At least not in a portable, conforming way. You can (under certain limitations) provide specializations like class A { }; namespace std { template<> class numeric_limits {}; } but you can't otherwise add declarations to std. There are several reasons for this limitation. AFAIK the committee discussed the possibility to provide fwd versions of standard headers other than but decided not to do so. Genny. ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
[boost] Re: how to avoid inclusions?
Pavol Droba wrote: > I wanted to do something else: > > template struct trait_class >{ > >} > >template struct trait_class > >{ > >} > > without #include > > Is this possible? Or is there a way how to achieve the same efect, but without > including ? > > I see, that is probably isn't .. > > Pavol > ___ > Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost Pavol Could you put each specialisation in a separate header file and arrange only to include the ones which you need, the vector one when you include etc? Just a thought John ___ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost