From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 914 invoked by alias); 7 Aug 2009 14:16:41 -0000 Received: (qmail 885 invoked by uid 22791); 7 Aug 2009 14:16:40 -0000 X-SWARE-Spam-Status: No, hits=1.2 required=5.0 tests=BAYES_50,J_CHICKENPOX_45,J_CHICKENPOX_46 X-Spam-Check-By: sourceware.org Received: from office.m-10.ru (HELO office.m-10.ru) (213.234.223.140) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 07 Aug 2009 14:16:31 +0000 Received: from [195.218.190.221] (account max@office.dgroup.ru) by office.m-10.ru (CommuniGate Pro WEBUSER 5.1.2) with HTTP id 217729467; Fri, 07 Aug 2009 18:16:24 +0400 From: "Maxim Dementiev" Subject: Asymmetry of user-difined swap and distance To: libstdc++@gcc.gnu.org, gcc@gcc.gnu.org Date: Fri, 07 Aug 2009 18:01:00 -0000 Message-ID: MIME-Version: 1.0 Content-Type: text/plain;charset="utf-8";format="flowed" Content-Transfer-Encoding: 8bit Mailing-List: contact gcc-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-owner@gcc.gnu.org X-SW-Source: 2009-08/txt/msg00132.txt.bz2 Hi, Let's have a look at std::pair<>::swap and std::lower_bound<> implementations. 1. pair::swap in http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/include/bits/stl_pair.h?view=markup void swap(pair& __p) { using std::swap; swap(first, __p.first); swap(second, __p.second); } 2. lower_bound in http://gcc.gnu.org/viewcvs/trunk/libstdc%2B%2B-v3/include/bits/stl_algo.h?view=markup _DistanceType __len = std::distance(__first, __last); Now we need to use user-defined versions of swap and distance for corresponding types when we work with STL. It means that swap for user types could be defined either in std namespace or in the user type namespace (argument-dependent name lookup). On the other hand, distance (advance, etc.) for user types must be defined in std namespace. How come? Why this asymmetry? Should we always extend std namespace? Regards, Maxim P. Dementiev