Skip to content

Instantly share code, notes, and snippets.

@darealshinji
Created January 10, 2024 04:32
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 darealshinji/21c31456c4accb43e91d0b6ee825b41d to your computer and use it in GitHub Desktop.
Save darealshinji/21c31456c4accb43e91d0b6ee825b41d to your computer and use it in GitHub Desktop.
#include <iostream>
/*
./bootstrap.sh --with-libraries=filesystem,url
./b2 -j4 link=static variant=release cxxflags="-O3 -ffunction-sections -fdata-sections"
g++ -O3 -Wall -Wextra -I. ../boost_misc.cpp -o ../boost_misc -Lstage/lib -lboost_filesystem -lboost_url -s -Wl,--gc-sections
*/
/* generate UUID (header-only) */
#include <boost/lexical_cast.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/uuid/random_generator.hpp>
/* get program location [-lboost_filesystem] */
#include <boost/dll/runtime_symbol_info.hpp>
#include <boost/filesystem.hpp>
/* convert URI to path [-lboost_url] */
#include <boost/url.hpp>
inline std::string uuid_random() {
return boost::lexical_cast<std::string>(boost::uuids::random_generator()());
}
inline std::string program_location() {
return boost::dll::program_location().string();
}
inline std::string uri_decode(const std::string &str) {
return boost::urls::url_view(str).path();
}
int main()
{
std::cout << "program location: " << program_location() << std::endl;
std::cout << "random UUID: " << uuid_random() << std::endl;
const std::string uri = "file:///tmp/my%2dfile.txt";
std::cout << "decode URI: [" << uri << "] -> [" << uri_decode(uri) << ']' << std::endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment