Skip to content

Reintroduce OverloadSet#31

Merged
alt-graph merged 10 commits intomainfrom
feature/overload_set
May 26, 2025
Merged

Reintroduce OverloadSet#31
alt-graph merged 10 commits intomainfrom
feature/overload_set

Conversation

@alt-graph
Copy link
Copy Markdown
Member

This pull request reintroduces and updates the OverloadSet class template which had been part of GUL14 and was thrown out semi-accidentally with the removal of the variant.h header. It is still useful for use with std::visit(), and therefore it is reimported, updated, and moved into a new header file OverloadSet.h.

Discussion points:

  • GUL14 also had a helper function make_overload_set(). With C++17 template argument deduction guides, this function has lost its reason for existing. In the first commit, it is still present but deprecated. We could decide to keep it that way, but I prefer a clean break.
  • Should we keep OverloadSet in variant.h as it was in GUL14 for compatibility? I guess not, OverloadSet.h is a cleaner name.

alt-graph added 6 commits May 23, 2025 13:30
[why]
It is probably a leftover from the auto-conversion of GUL14.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
[why]
Both the OverloadSet class template and the make_overload_set() function
template were included in GUL14, but removed along with the variant.h
header in the transition to GUL17. However, at least the class template
is still useful in conjunction with std::visit().

[how]
Import both the class and the function template. Rewrite OverloadSet in
C++17 style with a deduction guide so it can be constructed directly
from an arbitrary list of lambdas. Deprecate the make_overload_set()
function because it no longer offers any benefit over instantiating an
OverloadSet directly. Import the original tests for make_overload_set().

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
[why]
The function call is equivalent to constructing an OverloadSet{...} in
place.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
[why]
The header is no longer related to std::variant in any way. It only
contains the OverloadSet type.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
[why]
The Catch2 header was already removed from GUL17 much earlier, and the
OverloadSet.h header file should be included with gul.h like almost all
other header files.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
[why]
We should document that we have re-introduced the OverloadSet class
template into the library.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
@alt-graph alt-graph self-assigned this May 23, 2025
@alt-graph alt-graph added the enhancement New feature or request label May 23, 2025
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR reintroduces the OverloadSet class template in its own header, updates the library’s umbrella and build scripts to include it, and adds corresponding unit tests.

  • Add OverloadSet.h with the class template and C++17 deduction guide
  • Register the new header in meson.build and include it in gul.h
  • Add tests in tests/test_OverloadSet.cc and update build configurations
  • Remove a stale traits.h_ file and update changelog in data/doxygen.h

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
tests/test_OverloadSet.cc Add unit tests for the new OverloadSet behavior
tests/meson.build Register test_OverloadSet.cc in the test suite
include/gul17/traits.h_ Remove legacy traits.h_ file
include/gul17/meson.build Add OverloadSet.h to the list of standalone headers
include/gul17/gul.h Include OverloadSet.h in the main umbrella header and bump year
include/gul17/OverloadSet.h New header defining OverloadSet and its deduction guide
data/doxygen.h Document the reintroduction of OverloadSet in the changelog
Comments suppressed due to low confidence (4)

tests/test_OverloadSet.cc:2

  • The Doxygen \file annotation shows test_variant.cc instead of test_OverloadSet.cc. Update it to match the actual filename.
* \file   test_variant.cc

include/gul17/OverloadSet.h:2

  • The Doxygen \file annotation should refer to OverloadSet.h instead of variant.h.
* \file    variant.h

include/gul17/OverloadSet.h:24

  • The header guard macro should be renamed to GUL17_OVERLOADSET_H_ to match OverloadSet.h.
#ifndef GUL17_VARIANT_H_

include/gul17/OverloadSet.h:3

  • [nitpick] The header comment mentions make_overload_set(), but no such function is defined here. Either remove this reference or add the deprecated function implementation.
* \brief   Implementation of the OverloadSet class template and the make_overload_set() function template.

alt-graph added 3 commits May 23, 2025 14:29
[why]
Both should follow the renaming of the file to OverloadSet.h.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
[why]
It should follow the renaming of the file to test_OverloadSet.h.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
[why]
The function has been removed from the file.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
Copy link
Copy Markdown
Member

@Finii Finii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the removed file traits.h_ 🤔 🤷‍♀️

This looks 100% like the example on cppreference.com, which given the extreme small size of piece of code, may be coincidence, or you actually took that.
Maybe mention something like 'taken from' or 'insopied by' if the code actiually came from somewhere else.

image

Copy link
Copy Markdown

@Seim2k17 Seim2k17 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetic date changes

[why]
The original design of GUL14's OverloadSet class was inspired by the
"overloaded" class proposed in that book.

Signed-off-by: Lars Froehlich <lars.froehlich@desy.de>
@alt-graph
Copy link
Copy Markdown
Member Author

This looks 100% like the example on cppreference.com, which given the extreme small size of piece of code, may be coincidence, or you actually took that. Maybe mention something like 'taken from' or 'insopied by' if the code actiually came from somewhere else.

I think I originally got the idea for GUL14 from "A Tour of C++", and the class from the cppreference article looks very much like that one. But then... there are not many ways to skin that cat. In any case, I have added a reference to Bjarne's book.

@alt-graph
Copy link
Copy Markdown
Member Author

Thanks for the review, @Finii and @Seim2k17!

@alt-graph alt-graph merged commit 36bf248 into main May 26, 2025
3 checks passed
@alt-graph alt-graph deleted the feature/overload_set branch May 26, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants