Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a header with constants #234

Merged
merged 5 commits into from
Nov 1, 2023
Merged

Add a header with constants #234

merged 5 commits into from
Nov 1, 2023

Conversation

jmcarcell
Copy link
Member

Useful for HEP-FCC/k4SimGeant4#55 and key4hep/k4EDM4hep2LcioConv#32 and other places so that we can set the same value in all places consistently.

More constants can be added if there are suggestions.

BEGINRELEASENOTES

  • Add a constant for CellIDEncoding. Usage:
#include "edm4hep/Constants.h"

std::cout << edm4hep::CellIDEncoding << std::endl;

ENDRELEASENOTES

include/Constants.h Outdated Show resolved Hide resolved
Copy link
Collaborator

@andresailer andresailer left a comment

Choose a reason for hiding this comment

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

Thanks!

#ifndef EDM4HEP_CONSTANTS_H
#define EDM4HEP_CONSTANTS_H

#include <string>
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
#include <string>
#include <string_view>

Copy link
Contributor

Choose a reason for hiding this comment

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

Actually if we make it const char* we don't need any include here.

#include <string>

namespace edm4hep {
inline constexpr std::string_view CellIDEncoding = "CellIDEncoding";
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
inline constexpr std::string_view CellIDEncoding = "CellIDEncoding";
inline static constexpr auto CellIDEncoding = "CellIDEncoding";

I think making this a static const char* makes it easier to consume for things that take a const std::string& as a string_view will lead to

error: invalid initialization of reference of type 'const std::string&' {aka 'const std::__cxx11::basic_string<char>&'} from expression of type 'const std::string_view' {aka 'const std::basic_string_view<char>'

compiler explorer example

Copy link
Contributor

Choose a reason for hiding this comment

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

This will also still work if functions take a string_view as argument.

Copy link
Member Author

@jmcarcell jmcarcell Nov 1, 2023

Choose a reason for hiding this comment

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

I made it const char* (explicit in case someone checks the header); inline can be dropped since it's static

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Introduce commonly used constants
3 participants