stan-dev / stan-dev/math

convert std::stringstream message use to one-liners

Open
#590 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

code cleanup good first issue
Dominant language
C++
Stars
839
Forks
220
Avg merge
2d 4h
Merged PRs (30d)
14

Description

Summary:

We have a lot of code to convert to strings that uses stringstream as a builder:

std::stringstream ss;
ss << "foo" << x << std::endl;
std::string s = ss.str();

I'm pretty sure this is OK as a one-liner:

std::string s = (std::stringstream() << "foo" << x << std::endl).str();

I tested that it works on clang++ and g++ in a simple case. And I think it should work in general because str() returns a copy:

http://www.cplusplus.com/reference/sstream/stringstream/str/

The next question is whether the pattern could be used as an argument, and I think so given that the string is copied.

It would be even better if we could do this without explicitly including <sstream>. But there's nothing in Stan that's automatically brought in, so there's nowhere to put a typedef in stan::math that will automatically get picked up in every file.

Current Version:

v2.16.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No files or tests are named. Start by searching the repository for the shown std::stringstream builder pattern and inspect each use before deciding whether the one-liner is safe; done means applicable conversions are made without breaking the existing build or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.