glslViewer icon indicating copy to clipboard operation
glslViewer copied to clipboard

Fix: Promote project's standards to `C++17`

Open tcoyvwac opened this issue 1 year ago • 1 comments

  • As titled. :tada:
  • Many greater benefits compared to C++11, especially to do with constexpr, lambdas, and standard algorithms.
  • This gives developers tools to refactor the codebase and to express intent of code, in a much more simple way, (with a focus) to other developers reading the project's code.

tcoyvwac avatar Aug 25 '22 17:08 tcoyvwac

Due to a discovery in building PR:#319; because of an interesting characteristic highlighted during the Build (windows-latest) CI chain, this PR may have a follow-up PR to be promoted to C++20! :rocket:


Explanation: It seems that Build (windows-latest) is quite "strict" with some C++ nice features which other compilers accept pre-C++20! :disappointed:

This feature is called "Designated Initializer Lists"

  • https://en.cppreference.com/w/cpp/language/aggregate_initialization#Designated_initializers

So condensely explained, instead of being able to write the terse shortform: :smiling_face_with_tear:

union render_pass_args_t { // <-- [2]: Note: can use the union datatype for a bonus combo!
    const vera::Fbo* const fbo;
    const BuffersList* const fbolist;  // using BuffersList = std::vector<vera::Fbo*>;
};
struct vtable_render_pass_t{
    using func_sig_t = auto (*)(const std::string&, Uniforms&, const render_pass_args_t&, render_ui_t&)-> void;
    const std::string prompt_id;
    const render_pass_args_t process_info;
    const func_sig_t process_render_pass;
};
const auto render_pass_table = { vtable_render_pass_t
    {"u_buffer", {}, do_pass_singlebuffer}
    , {"u_scene", {&m_sceneRender.renderFbo}, do_pass_scene}
    , {"u_sceneBuffer", {.fbolist = &m_sceneRender.buffersFbo}, do_pass_scenebuffer} // <-- [1] for "Build (windows-latest)", this is "technically" a c++20 feature.
    , {"u_sceneDepth", {&m_sceneRender.renderFbo}, do_pass_scenedepth}
};

...we must be "strict" and write the very bluntish and verbose longform! (For Build (windows-latest) to be happy!) :scream:

struct render_pass_args_t {  // <-- [2]: Warning: strict-mode C++11, and so we have to use struct datatype declaration!
    const vera::Fbo* const fbo;
    const BuffersList* const fbolist;  // using BuffersList = std::vector<vera::Fbo*>;
};
struct vtable_render_pass_t{
    using func_sig_t = auto (*)(const std::string&, Uniforms&, const render_pass_args_t&, render_ui_t&)-> void;
    const std::string prompt_id;
    const render_pass_args_t process_info;
    const func_sig_t process_render_pass;
};
const auto render_pass_table = { vtable_render_pass_t
    {"u_buffer", {nullptr, nullptr}, do_pass_singlebuffer}
    , {"u_scene", {&m_sceneRender.renderFbo, nullptr}, do_pass_scene}
    , {"u_sceneBuffer", {nullptr, &m_sceneRender.buffersFbo}, do_pass_scenebuffer} // <-- [1]: Boo. :( All fields must be declared for everything, to make "Build (windows-latest)" happy!
    , {"u_sceneDepth", {&m_sceneRender.renderFbo, nullptr}, do_pass_scenedepth}
};

If programming (OO) is all about "message passing"[1], it's disappointing and unfortunate that this nice feature is hidden behind C++20 on Build (windows-latest)! :disappointed:

  1. https://en.m.wikipedia.org/wiki/Smalltalk#History

tcoyvwac avatar Dec 25 '22 23:12 tcoyvwac