News for hackers. Stuff that matters.
Re:Circle: C++ Automation Language by justicezyx on Saturday October 16, 2021 @02:50PM (#28890350)
This seems useful for code generation. Cannot relate this to any previous problems I encountered using c++

Any other interesting use of this?

Re:Circle: C++ Automation Language by seanbax on Saturday October 16, 2021 @07:03PM (#28892350)
My favorite use is putting user-defined attributes on data members, and using reflection to generate a UI to manipulate those values. I do it with these shadertoys:

https://github.com/seanbaxter/shaders#reflection-and-attribu...

Just mark your declarations up with custom attributes:

    [[.imgui::range_float {  .1,  5 }]] float Zoom = 1.5;
    [[.imgui::range_float {   0,  1 }]] float Speed = .15;
    [[.imgui::range_float {  .1,  1 }]] float XScale = .3;
    [[.imgui::range_float {   0, .5 }]] float YScale = .2;
Then loop over the members with a meta for, and emit widget code that's guided by the attribute kind and data. These attributes each define a scrollbar.

The kind of data you reflect over will likely come from within the program.

Re:Circle: C++ Automation Language by nikki93 on Saturday October 16, 2021 @08:43PM (#28892968)
Nice! This is definitely my main usecase for reflecty things lately, along with serialization for the data (game engine scenarios). I've been doing static reflection + attributes through this: https://godbolt.org/z/enh8za4ja Which actually comes out to a not-so-bad syntax and the attributes can be read constexpr (some limitations though: simple aggregate-y structs, and all reflected fieds must appear before non-reflected ones).

Lately I've been working on a Go (pretty small subset -- no GC or concurrency) to C++ compiler and generating meta stuff as part of it. Mostly because I like how focused Go's syntax is and also it having an official parser and type checker in the standard library makes things pretty quick to get started.

I should play with Circle some time! It's definitely touching on a lot of the desired things from a metaprogramming layer.

Re:Circle: C++ Automation Language by jcelerier on Sunday October 17, 2021 @01:55AM (#28894296)
In c++ there are some hacks that can start to help getting someswhere close (https://ossia.io/posts/reflection/) but this solution with attributes is what everyone dreams of
Re:Circle: C++ Automation Language by bialpio on Saturday October 16, 2021 @03:38PM (#28890765)
Seems that it could be used to solve an old-time classic: generate a mapping from an enum value to its string representation. Another use case that comes to my mind is maybe automating test case generation. Occasionally I was running into situations where I thought code generation could be useful, but not sure what could be a "killer app" equivalent for this feature.

Related topic: standardizing reflection in c++. https://youtu.be/ARxj3dfF_h0 https://en.cppreference.com/w/cpp/keyword/reflexpr

Re:Circle: C++ Automation Language by seanbax on Saturday October 16, 2021 @06:53PM (#28892294)
Enum to string is a one-line expression in Circle: https://godbolt.org/z/93f5o77zv

Circle has dozens of special traits for accessing useful stuff about types, packs, etc. Don't need to overengineer such a simple thing.

Re:Circle: C++ Automation Language by malkia on Saturday October 16, 2021 @08:11PM (#28892773)
Re:Circle: C++ Automation Language by pisssip on Sunday October 17, 2021 @06:00AM (#28895261)
What’s wrong with an array
Re:Circle: C++ Automation Language by ggrrhh_ta on Saturday October 16, 2021 @04:41PM (#28891295)
that would be great :-)
Re:Circle: C++ Automation Language by rahimiali on Saturday October 16, 2021 @04:25PM (#28891159)
Imagine using this to build a balzingly fast serialization library that you’d use like protobufs. Or to explore lots of configurations of your code to search for the variant that runs fastest. Or to write a linear algebra library that doesn’t generate temporary values that are dynamically allocated.
Re:Circle: C++ Automation Language by vlovich123 on Saturday October 16, 2021 @08:10PM (#28892767)
Imagine you want to intern your printf strings somewhere so that your logs look like logit(“some message providing more details. %s, %d”, someStringArg, someIntArg). Typically you have to serialize the whole thing and store it. However, if you save the compile string into a separate database at compile time and the call site transforms to logit(msgId, someStringArg, someIntArg), then you’ve reduced your logging cost to the cost of serializing the log message which is drastically cheaper, faster and takes less space in whatever log storage system you use. You only pay the formatting cost when you go to display the logs to a person.