Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

19
  • “What if you need the sentinel at compile time”. How often do you need an array with a size of -1? Commented Dec 19, 2018 at 22:29
  • “You can’t store different compile time versions in a container” If you need runtime polymorphism, use the runtime version. Commented Dec 19, 2018 at 22:32
  • “You can’t pass around an instance of the compile time version”. You wouldn’t typically store just a single property in a class like this. std::span stores a runtime pointer and a runtime or compile time size. std::array stores runtime elements and a compile time size. You can call a static function like this compileTimeInstance.getProp(). This means that you can pass either the runtime or compile time version to a template function. Commented Dec 19, 2018 at 22:36
  • You could pass either a std::array or a std::vector to a template function and it will just work. Commented Dec 19, 2018 at 22:44
  • @Kerndog73 1. Where did you ever speak of arrays? The question was more general. 2. But you don't need a template specialisation for, have a separate class. 3. Have a close look: std::spanand std::array both have one single template parameter for the type. As mentioned, Type<10> and Type<12> are different types, you cannot place both of them into the same array. Do you want all of your configuration objects to return the same value? 4. see 3. Commented Dec 20, 2018 at 5:37