Skip to content

Instantly share code, notes, and snippets.

@brentalanmiller
Created August 24, 2018 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brentalanmiller/e5f7ab88af695540b8068881ac3fa30f to your computer and use it in GitHub Desktop.
Save brentalanmiller/e5f7ab88af695540b8068881ac3fa30f to your computer and use it in GitHub Desktop.
Boost UUID truncates long string UUIDs without error
#include <iostream>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/string_generator.hpp>
int main() {
boost::uuids::string_generator gen;
boost::uuids::uuid u = {};
std::string test1 = "5E6086E2-B30E-40FB-84EC-419EDCDD4DB1";
std::string test2 = "D6FEDF2A-4B19-45C8-A040-A6CC2C206233-58886-000081F89D313161";
try {
u = gen(test1);
} catch (const std::runtime_error &e) {
std::cerr << "Invalid UUID in test1. Got: " << test1 << std::endl;
}
std::cout << "parsed test1: " << to_string(u) << std::endl;
try {
u = gen(test2);
} catch (const std::runtime_error &e) {
std::cerr << "Invalid UUID in test2. Got: " << test2 << std::endl;
}
std::cout << "parsed test2: " << to_string(u) << std::endl;
return 0;
}
parsed test1: 5e6086e2-b30e-40fb-84ec-419edcdd4db1
parsed test2: d6fedf2a-4b19-45c8-a040-a6cc2c206233
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment