Posts

Showing posts with the label Boost

C++ : Coding Standards by Example #1 (with Boost Beast)

Image
Today I've spent sometime doing a little different video, rather than just play about in code, whilst I played about I made a video of the time I had... Here is it... We cover: C++ Coding Standards Structured Programming Functional Programming Encapsulation Object Orientated Programming Building the Boost Libraries (1.67.0) Visual Studio 2017 Static Linking And generally spend time seeing how I turn gobble-de-gook code into something usable and maintainable against my own Coding Standards. Get the code yourself here:  https://github.com/Xelous/boostBeast

C++ boost::replace_all Slowed Me

I've just had myself into a complete frazzle, code yesterday was fast, rendering 120fps, the same code today was struggling to pass 11fps.  And it had me pulling my hair out, of which I have little left to spare. The problem? I had been processing strings for specific patterns and only replacing them, so a variable in my engine might have the value "SCORE" and it'd replace the players score value directly into the std::string instance for display. I however decided I wanted to compound all these reserved words to allow any value to contain any replaced value and also contain formatting, so I could so something like "You have scored %SCORE% today" and it'd just place the number in place. I turned to boost for this, boost::replace_all, to be specific, and I had about 45 pattern matches which would try to replace any instance of the string in place. However, this function does not look a head if the predicate is present in the source string, it's in fac...

C++ : The unrandom random number...

Image
I've been working in some C++, with boost to be precise, the machine I'm working towards finally has a processor with SSE3 in it, and so I've been to revisit the GUID generation code, boost specifies a couple of defines you can set up before incluiding the uuids header to help... #include <iostream> #ifndef BOOST_UUID_USE_SSE3 #define BOOST_UUID_USE_SSE3 #endif #include <boost/uuid/uuid.hpp> #include <boost/uuid/uuid_io.hpp> #include <boost/uuid/uuid_generators.hpp> #include <boost/lexical_cast.hpp> const std::string GetGuid(); int main () { for (unsigned int i(0); i < 100000; ++i) { std::cout << GetGuid() << "\r\n"; } } const std::string GetGuid() { boost::uuids::uuid l_guid = boost::uuids::random_generator()(); return boost::lexical_cast<std::string>(l_guid); } This code looks fairly innocuous, "GetGuid" is the key part, you may argue that you're always setting the random number gener...