From -5893515993485714981 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f78e5,8eebfdfe25d22b37 X-Google-Attributes: gidf78e5,public X-Google-ArrivalTime: 2001-12-22 01:20:02 PST Return-Path: X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!comp-std-cpp-robomod!not-for-mail X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov) From: "Richard Smith" Newsgroups: comp.std.c++ Subject: Re: C++0x: vector::pack() Message-ID: <1008936696.14508.0.nnrp-10.3e31d362@news.demon.co.uk> References: <3BD40077.4AB9D0A2@divalsim.it> <3bd464b5$0$8508$ed9e5944@reading.news.pipex.net> <3BD4B660.F3C7606@wizard.net> <3bd539f4$0$230$cc9e4d1f@news.dial.pipex.com> <3BD5FF27.55AFFDFC@wizard.net> <9vqs6m$58p$2@news.tuwien.ac.at> <3C228128.B4CC8CE3@wizard.net> X-NNTP-Posting-Host: mailgate.transversal.co.uk:62.49.211.98 X-Trace: news.demon.co.uk 1008936696 nnrp-10:14508 NO-IDENT mailgate.transversal.co.uk:62.49.211.98 X-Complaints-To: abuse@demon.net X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 Approved: Fergus Henderson , moderator of comp.std.c++ Date: Sat, 22 Dec 2001 03:16:56 CST Lines: 69 Xref: archiver1.google.com comp.std.c++:8699 "James Kuyper Jr." wrote in message news:3C228128.B4CC8CE3@wizard.net... > Christopher Eltschka wrote: > ... > > It would not have to be undefined behaviour, if the (non-)existance of > > the function is detectable by code, say through an allocator_traits. > > As a general rule, I distrust solutions which depend upon traits > classes. A traits template will give you the correct information only if > someone remembers to specialize the template for each new class it might > be applied to. You can usually choose a "safe" default when it isn't > specialized, but that means that in general the traits template can't be > counted on to correctly the question it's designed to answer. It is possible to write a traits class that automagically detects whether a member function of a known signature exists. I think this code is legal and does that, unfortunately I've yet to find a compiler that can actually cope with it! Even Comeau segfaults with it ;-(. namespace details { template struct type_fwd { typedef T type; }; template struct has_reallocate { enum { value = false }; }; template struct has_reallocate < T, typename type_fwd < T, void *(T::*)(void *, size_t, size_t), &T::reallocate >::type > { enum { value = true }; }; } template struct allocator_traits { enum { has_reallocate = details::has_reallocate::value }; }; I admit the code isn't pleasant, but it does avoid having to remember to specialise allocator_traits for every new allocator. -- Richard Smith --- [ comp.std.c++ is moderated. To submit articles, try just posting with ] [ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ] [ --- Please see the FAQ before posting. --- ] [ FAQ: http://www.research.att.com/~austern/csc/faq.html ]