[pdal] Fwd: [Boost-users] Using boost::uuids::uuid as a map index

Mateusz Łoskot mateusz at loskot.net
Thu Dec 22 19:49:55 EST 2011


Hi,

PDAL/libLAS make use of GUID/UUID, so I think the post attached
may be of interest here:


---------- Forwarded message ----------
From: Andy Tompkins <atompkins at fastmail.fm>
Date: 22 December 2011 17:12
Subject: Re: [Boost-users] Using boost::uuids::uuid as a map index
To: "boost.org" <boost-users at lists.boost.org>


On Sun, Dec 11, 2011, at 12:22 AM, Klaim - Joël Lamotte wrote:

Hi,

On Sat, Dec 10, 2011 at 17:22, Tim Burgess <tim at raisedbar.net> wrote:

All look-ups within the map based on the UUID then fail, as adding the
object to the map is essentially a copy operation and UUID is non-copyable,
so new unique identifiers were generated.  I then tried:

Std::map <boost::uuids::uuid *, myClass*> myMap;


AFAIK uuid is copyable as it's a POD.


Correct, boost::uuids::uuid is copyable, it is a POD.

It can be used as the key in an std::map.  I have created a simple
test for this and checked it into trunk
(http://svn.boost.org/svn/boost/trunk/libs/uuid/test/test_uuid_in_map.cpp).
 It passes.  I have also attached the file.

I'm not sure where the problem is with your code.  Could you provide a
more complete example?


However, I don't know about this problem but I remember having failed
to make uuid a key of map (I don't remember the reason).

If that can help you, I'm using a workaround to allow this : I convert
the uuid to std::string (using the generator function) and use it in
my whole application to allow finding by uuid from maps. That's
obviously more expensive but it works fine.


Joël Lamotte




Regards,
Andy.

_______________________________________________
Boost-users mailing list
Boost-users at lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users


-- 
Mateusz Loskot, http://mateusz.loskot.net
Charter Member of OSGeo, http://osgeo.org
Member of ACCU, http://accu.org
-------------- next part --------------
//  (C) Copyright Andy Tompkins 2011. Permission to copy, use, modify, sell and
//  distribute this software is granted provided this copyright notice appears
//  in all copies. This software is provided "as is" without express or implied
//  warranty, and with no claim as to its suitability for any purpose.

// Distributed under the Boost Software License, Version 1.0. (See
// accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

// libs/uuid/test/test_uuid_in_map.cpp  -------------------------------//

#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <map>

#include <boost/detail/lightweight_test.hpp>

int main(int, char*[])
{
    boost::uuids::random_generator gen;

    boost::uuids::uuid u1 = gen();
    boost::uuids::uuid u2 = gen();
    boost::uuids::uuid u3 = gen();

    std::map<boost::uuids::uuid, int> uuid_map;
    uuid_map[u1] = 1;
    uuid_map[u2] = 2;
    uuid_map[u3] = 3;

    BOOST_TEST_EQ(1, uuid_map[u1]);
    BOOST_TEST_EQ(2, uuid_map[u2]);
    BOOST_TEST_EQ(3, uuid_map[u3]);

    return boost::report_errors();
}


More information about the pdal mailing list