I'm working on a design implementation where I want the input to be selected from a specific set of characters for its string literal representation.
Consider the following set of classes:
class enum BaseType {
BINARY = 2,
OCTAL = 8,
…
I was reading source code of string_view, and found that operator== accepts parameters by value.
template
constexpr bool
operator==(basic_string_view<_CharT, _Traits> __x,
…
I want to define a macro as a string and later at compile time include code based on string comparison:
#include
#include
constexpr bool strings_equal(char const * a, char const * b) {
return…
This function parses input line into argument like shell(bash,ksh,fish) does. I.e. looks in input string parts separated by whitespaces or tabs:
auto parse_args(string_view const& line){
vector args;
size_t pos_begin = 0,…
So, I was reading about using enum as part of the new C++2a standards here and came across the following code:
enum class rgba_color_channel { red, green, blue, alpha};
std::string_view to_string(rgba_color_channel channel) {
switch (my_channel)…
I want to "migrate" to C++17 and am researching it.
I found that this:
https://gcc.godbolt.org/z/sPnsEM
#include
#include
int main(){
return
(std::is_standard_layout_v ? 10 : 20)
+
…
C++17 introduced hash. When writing my own custom hashes I want to reuse the STL implementation of the string hash.
Is std::hash()("Hello, world") slower than std::hash()("Hello, world")? Is it the…
For some time I’ve used Boost’s flat_map as my go-to associative collection, for the reasons explained cited on their documentation intro, and (originally) the fact that it gave newer features before the compiler’s std implementation, and it was the…
I have a small program that compiles on GCC but not on MSVCwhich compiler isn't following the standard for constexpr string_view comparison?
#include
#include
int main(int argc, char **argv) {
const constexpr auto a =…
Suppose we've read the content of a text file into a stringstream via
std::ifstream file(filepath);
std::stringstream ss;
ss << file.rdbuf();
and now want to process the file line-by-line. This can be done via
for (std::string line;…
How would you convert a std::string_view to a null-terminated c string? I've passed a string_view into a function, and need to pass that into another function, which takes a const char* parameter. However, looking at this documentation for…
This code does not compile. I assume this is because string_view is not a LiteralType, which violates the constexpr function conditions (http://en.cppreference.com/w/cpp/language/constexpr):
constexpr std::size_t find_space(std::string_view sv)…
I was playing around with std::string_view with different compilers and noticed that each compiler prints out different sizes when initializing the std::string_view with a non-null terminated char array.
It seems that every compiler prints out the…