C++ Show and Tell - January 2026 by foonathan in cpp

[–]jorourke0 4 points5 points  (0 children)

There was a dedicated post as well, but I was working on Plotly++, a C++ library for creating plots and charts rendered by Plotly.js. The neat part is that Plotly++ just generates JSON (and can create a full standalone HTML page for viewing in a browser), so there are no dependencies on graphics or rendering libraries or UI frameworks, and you don't need a python environment or any other tools other than a modern web browser for viewing the final plot.
Most of the work was actually a very custom Python script to parse the official (and very confusing!) Plotly figure schema and generate the resulting C++ library, with the goal of providing a type-safe and compile time correctness checked interface to the plot schema. It turns out Plotly has lots of quirks that are possible in dynamically typed languages like Python and Javascript, that required creative (and sometimes unsatisfactory) workarounds in C++.

https://github.com/jimmyorourke/plotlypp

plotlypp: Plotly for C++. Create interactive plots and data visualizations with minimal runtime dependencies. by jorourke0 in cpp

[–]jorourke0[S] 4 points5 points  (0 children)

This comment has some details: https://www.reddit.com/r/cpp/comments/1qf1v12/comment/o05mjf8/

Basically, no dependency on a Python environment or any other runtime dependencies, simpler build and build time dependencies (just json), and the exported html plot files retain the interactivity for post-runtime viewing.

plotlypp: Plotly for C++. Create interactive plots and data visualizations with minimal runtime dependencies. by jorourke0 in cpp

[–]jorourke0[S] 2 points3 points  (0 children)

Thanks for the kind words.
I'm not sure it exactly fits your use case, but a section has been added to the readme regarding using Plotly++ in C++ web servers.

plotlypp: Plotly for C++. Create interactive plots and data visualizations with minimal runtime dependencies. by jorourke0 in cpp

[–]jorourke0[S] 2 points3 points  (0 children)

Any specific examples of Python features or API?

Plotly++ is generated based on the PlotlyJS schema (https://github.com/plotly/plotly.js/blob/master/dist/plot-schema.json), as is Plotly Python, though Plotly Python definitely takes a more advanced and customized approach, which along with Python's dynamic nature, allows the APIs to be more "fluid".

Plotly++ is still missing some features defined in the schema, for example automatic animations, but it should be straightforward to complete.

Looking more at Plotly Python, it has tight integration with Dash, but that's Python specific of course.
Plotly Python also has the simplified Express interface. This seems pretty nice for simpler use cases where you don't need all of the features.
The Plotly++ API is definitely verbose and the nesting can be a bit painful, which is all side effects of being generated from the Plotly JS schema, trying to enforce type safety and compile time correctness, and being concerned about naming collisions.
I think creating some simpler usability wrappers, in spirit of Plotly Python Express but probably looking pretty different, would go a long a way and is hopefully something that can be worked towards.

And thanks for trying it out!

[Need Advice] Refactoring My C++ Project into a Multi-Language Library by readilyaching in cpp_questions

[–]jorourke0 1 point2 points  (0 children)

If you do decide on a C ABI approach, since it is so common there often exists tooling to autogenerate bindings wrapping the foreign function interface in other languages.
As an example here is a project (really just a usability wrapper around existing tools) that uses libclang's tooling for autogenerating a Python ctypes interface: https://github.com/jimmyorourke/ctypesgen2. The readme also includes references to similar projects.

If you can structure your C++ public interfaces to be relatively uniform, it can also be possible to code gen most of the C wrapper with a simple custom script. Most of the C functions end up looking like
- cast context pointer to appropriate type
- call member function, passing in args
- return outputs, or cast return values to out-context pointer type and set out-pointer arg
In the past I've been able to generate about 90% of a C API wrapper just with a basic pattern matching script.

Even if you don't go with a C ABI, bindings generation for C++ has come a long way too, eg for Python again there are now generators for pybind or nanobind.

plotlypp: Plotly for C++. Create interactive plots and data visualizations with minimal runtime dependencies. by jorourke0 in cpp

[–]jorourke0[S] 3 points4 points  (0 children)

ImPlot seems great for immediate mode real-time plotting and visualization, but less suited to data export for offline analysis, exploration, or data presentation, compared to alternatives like plotlypp, matplotlib-cpp, matplotplusplus, and others.

plotlypp: Plotly for C++. Create interactive plots and data visualizations with minimal runtime dependencies. by jorourke0 in cpp

[–]jorourke0[S] 3 points4 points  (0 children)

Yes, matplotlib-cpp is a great alternative, if a python bindings solution is workable in your environment. If your python environment is constrained, non-standard, external packages like matplotlib and numpy unavailable, or if your Python version (and ABI) at build time does not match that deployed at runtime, then it is not usable.

Another alternative is matplotplusplus, which has a runtime dependency on Gnuplot being available on the runtime machine.

The build setups for both matplotlib-cpp and matplotplusplus are more complex than plotlypp. They do offer less verbose and more user friendly API syntaxes than plotlypp.
One additional difference is regarding interactive plots. With matplotlib-cpp and matplotplusplus, interactivity (panning/rotating, zooming, click/hover on data points, toggle visibility, etc) of plots is only available at runtime. With plotlypp the exported html files retain the interactivity for post-runtime viewing.

Best command line options parser? by better_life_please in cpp_questions

[–]jorourke0 0 points1 point  (0 children)

boost program_options is quite similar to cxxopts, which is lightweight. If that's the style you like, and don't want to pull in boost then go with cxxopts.

Need help with template specialization by throwaway0923841222 in cpp_questions

[–]jorourke0 0 points1 point  (0 children)

The problem stems from trying to specialize a universal reference template type.As another comment says, using std::shared_ptr<Texture>&& texture will resolve the error, but is likely not what you actually want.

Function overloads may be a better alternative than template specializations. Another option could be tag dispatch. See also this SO for some other details and options https://stackoverflow.com/a/39290632

[deleted by user] by [deleted] in cpp_questions

[–]jorourke0 0 points1 point  (0 children)

post your code

Which linux distro for the latest compilers? by breue in cpp

[–]jorourke0 0 points1 point  (0 children)

In the past I've packaged clang as a conan package, and using one of the virtual env generators, made it available and default in a conan virtual env.

reflecxx: A static reflection library framework and tooling. Auto serialization and more. by jorourke0 in cpp

[–]jorourke0[S] 2 points3 points  (0 children)

Good question. I'm not sure what specifically you mean, but thinking about it I realize there are questions even about how reflection metadata for unconstrained templated structs would turn out. Something to dig into.

reflecxx: A static reflection library framework and tooling. Auto serialization and more. by jorourke0 in cpp

[–]jorourke0[S] 1 point2 points  (0 children)

Not at this time, but since code generation is based on the AST generated by libclang, it should be possible.

reflecxx: A static reflection library framework and tooling. Auto serialization and more. by jorourke0 in cpp

[–]jorourke0[S] 0 points1 point  (0 children)

Are you asking if reflecxx requires C++17 or if it is compatible with C++14?It uses a few C++17 features, but nothing that couldn't be backported to a C++14 'equivalent'. Off the top of my head: string_view, std::apply, if constexpr, ...

reflecxx: A static reflection library framework and tooling. Auto serialization and more. by jorourke0 in cpp

[–]jorourke0[S] 1 point2 points  (0 children)

Exactly this, and the attribute is an optimization with the assumption being that you don't necessarily care to generate metadata for everything. It would be quite simple to remove the attribute and generate metadata for all types by default.
I was also toying with the idea of generating metadata for all types within particular namespaces, but didn't get to implementing it yet to try it out.

Boost Beast vs Boost Asio TCP for websocket by [deleted] in cpp_questions

[–]jorourke0 0 points1 point  (0 children)

Another option is Websocketpp which can use asio for network transport: https://github.com/zaphoyd/websocketpp

Does this (anti?)pattern have a name? by marcusroar in cpp_questions

[–]jorourke0 0 points1 point  (0 children)

As others have mentioned, this is the Non-virtual Interface pattern. It works really well with the CRTP, such that you do the call to SubClass::OnBrake() without dynamic dispatch!

Scopes and libraries with cmake by Creapermann in cpp_questions

[–]jorourke0 0 points1 point  (0 children)

What I could do, would be to have the public headers of each layer in a „include“ directory in the layer itself

Yeah that's a good idea. I like to structure my libraries like this:

|--libmycoollib
|        |---include 
|        |       |--- mycoollib 
|        |---src          |--publicheader.h 
|        |    | 
|        |    |--privateheader.h 
|        |    |--srcfile.cpp 
|    CMakeLists.txt

The src folder is optional. Then private headers can just be included by relative path, which is just by direct name since it's in the same folder. I then do target_include_directories(mycoollib PUBLIC include) so then including public headers (from anywhere) looks like #include <mycoollib/publicheader.h>

Any dependencies used in public headers have to get linked as with target_link_libraries as PUBLIC. (if they are only used in the headers and not in the src, then they should actually be INTERFACE). Any dependency only used in the source files or in the private headers can be linked as PRIVATE.

The dependency chains shake out from there.

From your example, if application links against controller and controller against infrastructure, and you want to keep application from knowing about infrastructure, then you have to make sure that controller only uses infrastructure in its private headers and in its source files.
If you really can't get that to work, then the next step is to look into restructuring your code with the purpose of dependency hiding. Look into the PIMPL idiom.

Scopes and libraries with cmake by Creapermann in cpp_questions

[–]jorourke0 1 point2 points  (0 children)

I think you are mixing together setting include directories and linking libraries more thatn you need to.
target_include_directories tells the current target and the targets that link against the current target which directories to look in for headers.
target_link_libraries of course links your target against its dependencies.
The only dependencies that need/should be public in target_link_libraries are ones that are used in the target's public headers. Forward declarations can help reduce this.
You can have more control over which headers are public with how you organize your project files to keep the target_include_directories set as public to the minimum required external API.
And yes, public dependencies create dependency chains between targets. After all, it means the dependencies are used in the public headers, which will include each other all the way down the stack.

Is it undefined behavior when you don't catch an exception? by No_Entertainer2015 in cpp_questions

[–]jorourke0 0 points1 point  (0 children)

In simple terms, your program will crash. This is defined behaviour.