C++

2068 readers
5 users here now

The center for all discussion and news regarding C++.

Rules

founded 2 years ago
MODERATORS
1
2
3
4
5
7
C++ with no classes? (pvs-studio.com)
submitted 3 weeks ago* (last edited 3 weeks ago) by CodiUnicorn@programming.dev to c/cpp@programming.dev
6
 
 

Hi! ✌️ I need to generate some string in C++ with random characters that can use all letters from "a" to "z" (include capital letters), and all numbers from 0 to 9 there.

And for examples this should looks somehow like this:

SnHXAsOC5XDYLgiKM5ly

Also I want to encrypt that string then by itself:

SnHXAsOC5XDYLgiKM5ly encrypt with SnHXAsOC5XDYLgiKM5ly key.

So, how can I do this in C++? 🤔

Thanks in advance!

7
 
 

So today I wanted to talk about a very cool example that Dan put together on the flight home from Sofia, while I was unconscious a few seats over: the ability to, at compile time, ingest a JSON file and turn it into a C++ object.

8
9
safe enum (programming.dev)
submitted 1 month ago* (last edited 1 month ago) by nodeluna@programming.dev to c/cpp@programming.dev
 
 

for anyone who doesn't know, this "-Werror=switch-enum" compiler option make the compiler throw an error if all of the enum values aren't explicitly handled in a "switch" statement


enum class colors {
        blue,
        red,
        purple,
}

void func(colors c)
{
        switch(c)
        {
                case colors::blue:
                        // do something
                        break;
                case colors::red:
                        // do something
                        break;
                default:
                        // do something
                        break;
        }
}


int main()
{
        func(colors::blue);
}

this code doesn't compile on clang and gcc with the option "-Werror=switch-enum" because the "colors::purple" isn't explicitly handled. be aware that it doesn't throw a compiler error for "if" statements if one of the values isn't handled

9
 
 

It's not fully finished yet, but it's getting there, and i didn't write documentation beyond the README.md and tests/test.cpp but I'd like some feedback on it.

features

  • It's a header only library that's currently < 3000 loc
  • no 3rd-party dependencies
  • support for being imported as a module
  • supports inserting std containers into json nodes
  • highly type safe, which is made possible by using concepts
  • easy-to-use object/array iterations
  • easy-to-use type casting from json value to native c++ types which is enabled by std::variant and concepts
  • exception-free parsing and value casting.
  • modern error handling using "expected" type
  • exception-free node.try_at("key") access
  • and more

edit:

documentation link: https://nodeluna.github.io/ljson

10
 
 
11
12
 
 

Herb Sutter just announced that the verdict is in: C++26, the next version of C++, will include compile-time reflection.

Reflection in programming languages means that you have access the code’s own structure. For example, you can take a class, and enumerate its methods. For example, you could receive a class, check whether it contains a method that returns a string, call this method and get the string. Most programming languages have some form of reflection. For example, the good old Java does have complete reflection support.

13
 
 

Today marks a turning point in C++: A few minutes ago, the C++ committee voted the first seven (7) papers for compile-time reflection into draft C++26 to several sustained rounds of applause in the room.

14
 
 

Let’s take a problem that can only be solved with Reflection and compare what the solution would look like between:

  • the C++26 value-based model
  • the Reflection Technical Specification (TS)’s type-based model
15
 
 

Vcc - the Vulkan Clang Compiler, is a proof-of-concept C and C++ compiler for Vulkan leveraging Clang as a front-end, and Shady our own research IR and compiler. Unlike other shading languages, Vcc aims to stick closely to standard C/C++ languages and merely adds a few new intrinsics to cover GPU features. Vcc is similar to CUDA or Metal in this regard, and aims to bring the advantages of standard host languages to Vulkan shaders.

Key Features

Vcc supports advanced C/C++ features usually left out of shading languages such as HLSL or GLSL, in particular raising the bar when it comes to pointer support and control-flow:

  • Unrestricted pointers
    • Arithmetic is legal, they can be bitcasted to and from integers
  • Generic pointers
    • Generic pointers do not have an address space in their type, rather they carry the address space as a tag in the upper bits.
  • True function calls
    • Including recursion, a stack is implemented to handle this in the general case
  • Function pointers
    • Lets you write code in a functional style on the GPU without limitations
  • Arbitrary goto statements - code does not need to be strictly structured !

Many of these capabilities are present in compute APIs, but are not supported in most graphics APIs such as DirectX or Vulkan. We aim to address this gap by proving these features can and should be implemented. More on why we think that’s important.

16
17
18
19
20
21
22
23
24
25
view more: next ›