Skip to content

cpp: add template_streamop generation with runtime/compiler test coverage#3312

Open
zsy056 wants to merge 1 commit intoapache:masterfrom
zsy056:template_stream_op
Open

cpp: add template_streamop generation with runtime/compiler test coverage#3312
zsy056 wants to merge 1 commit intoapache:masterfrom
zsy056:template_stream_op

Conversation

@zsy056
Copy link
Contributor

@zsy056 zsy056 commented Feb 17, 2026

Add template_streamop support in the C++ generator so generated operator<< and printTo can target generic stream-like output types. Keep default behavior unchanged when the option is not set (std::ostream signatures remain). Add compiler/runtime coverage for template generation, friend declaration correctness, enums, and collection printing.

default:

std::ostream& operator<<(std::ostream& out, const SimpleStruct& obj);

class SimpleStruct {
public:
  void printTo(std::ostream& out) const;
};

with template_streamop:

template <typename OStream_>
OStream_& operator<<(OStream_& out, const SimpleStruct& obj);

class SimpleStruct {
public:
  template <typename OStream_>
  void printTo(OStream_& out) const;
};
  • Did you create an Apache Jira ticket? (Request account here, not required for trivial changes)
  • If a ticket exists: Does your pull request title follow the pattern "THRIFT-NNNN: describe my issue"?
  • Did you squash your changes to a single commit? (not required, but preferred)
  • Did you do your best to avoid breaking changes? If one was needed, did you label the Jira ticket with "Breaking-Change"?
  • If your change does not involve any code, include [skip ci] anywhere in the commit message to free up build resources.

…rage

Add template_streamop support in the C++ generator so generated operator<< and printTo can target generic stream-like output types.
Keep default behavior unchanged when the option is not set (std::ostream signatures remain).
Add compiler/runtime coverage for template generation, friend declaration correctness, enums, and collection printing.

default:
```cpp
std::ostream& operator<<(std::ostream& out, const SimpleStruct& obj);

class SimpleStruct {
public:
  void printTo(std::ostream& out) const;
};
```

with `template_streamop`:
```cpp
template <typename OStream_>
OStream_& operator<<(OStream_& out, const SimpleStruct& obj);

class SimpleStruct {
public:
  template <typename OStream_>
  void printTo(OStream_& out) const;
};
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments