Skip to content

replace const char* arguments with std::string in error functions #460

@bob-carpenter

Description

@bob-carpenter

Summary:

Functions like

inline void out_of_range(
  const char* function,
  int max,
  int index,
  const char* msg1 = "",
  const char* msg2 = "");

uses const char* arguments where they should be using const std::string& in C++.

To avoid the performance hit of having to construct std::string instances when char* is being pased, we need to construct static standard strings in the calling functions:

static const std::string function_name = "foo";
static const std::string msg = "bar baz";
out_of_range(function_name, 5, 2, msg);

This way, each of the standard strings is only constructed once. They can't be constexpr and moved to compile time because std::string isn't a literal.

Current Version:

v2.13.0

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions