mentby.com
Blog | Jobs | Help | Signup | Login

loading

time variant uuid

Thu, 10 May 2012 10:13:45 -0700 Post Comments

This is not guaranteed to be true, t1 may be greater than t2.  It really
is random data used to create the uuid in this case.

Sadly, I have not yet implemented a time-based generator for uuids.  I
plan to create a few platform specific generators that wrap OS calls
that would do this.

If is is a time-based uuid, then the date and time can be extracted, but
not from a random-based, or name-based (uses a hash).

Regards,
Andy Tompkins

Using boost::uuids::uuid as a map index

Thu, 22 Dec 2011 09:13:30 -0800 Post Comments

Hi,

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
([2 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.

References

1. mailto:tim*******
2.  http://svn.boost.org/svn/boost/trunk/libs/uuid/test/test_uuid _in_map.cpp

//  (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();
}

boost.uuid typo error

Mon, 21 Nov 2011 14:03:21 -0800 Post Comments

On Monday, November 21, 2011 4:59 PM, "Paul A. Bristow"

Thanks.  I will fix the documentation.

It is on my todo list to change the docs to Quickbook.  It will likely
be awhile yet, only
because I haven't spent the (likely minimal) time to put it on my
machine and learn it.  It
there a small sample that I could start with, instead of starting from
scratch?  I started
with the sample html documentation from boost for what is currently
there for boost::uuids.

Thanks again,
Andy Tompkins
Group(s)
Profile Widget
Copy and paste this HTML code to your blog or website: