Skip to content

Commit

Permalink
Improve support for unusual C++ map types
Browse files Browse the repository at this point in the history
Summary:
Some C++ maps have an unusual reference / const_reference type.  For example, std::flat_map, which uses:

std::pair<const key_type&, mapped_type&>
std::pair<const key_type&, const mapped_type&>

We would previously hit an error like this:

```
thrift/lib/cpp2/protocol/Cpp2Ops.h:43:3: error: static assertion failed due to requirement 'sizeof(const Foo&) == ~0ULL': (only Thrift-generated classes are serializable)
```

Here I strip off the cvref qualifiers.

Reviewed By: vitaut

Differential Revision: D59979468

fbshipit-source-id: dc3b60ceb485ba0b0688ba0ccf7ab0b6544aa61b
  • Loading branch information
marksantaniello authored and facebook-github-bot committed Jul 20, 2024
1 parent 0112e10 commit a1c7a83
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions thrift/lib/cpp2/protocol/Cpp2Ops-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ class Cpp2Ops<
typedef typename std::remove_cv<
typename std::remove_reference<decltype(*value->begin())>::type>::type
PairType;
typedef typename PairType::second_type ValueType;
typedef folly::remove_cvref_t<typename PairType::second_type> ValueType;
uint32_t xfer = 0;
xfer += prot->writeMapBegin(
Cpp2Ops<KeyType>::thriftType(),
Expand All @@ -692,7 +692,7 @@ class Cpp2Ops<
typedef typename std::remove_cv<
typename std::remove_reference<decltype(*value->begin())>::type>::type
PairType;
typedef typename PairType::second_type ValueType;
typedef folly::remove_cvref_t<typename PairType::second_type> ValueType;
value->clear();
uint32_t size;
protocol::TType keytype, valuetype;
Expand All @@ -712,7 +712,7 @@ class Cpp2Ops<
typedef typename std::remove_cv<
typename std::remove_reference<decltype(*value->begin())>::type>::type
PairType;
typedef typename PairType::second_type ValueType;
typedef folly::remove_cvref_t<typename PairType::second_type> ValueType;
uint32_t xfer = 0;
xfer += prot->serializedSizeMapBegin(
Cpp2Ops<KeyType>::thriftType(),
Expand All @@ -731,7 +731,7 @@ class Cpp2Ops<
typedef typename std::remove_cv<
typename std::remove_reference<decltype(*value->begin())>::type>::type
PairType;
typedef typename PairType::second_type ValueType;
typedef folly::remove_cvref_t<typename PairType::second_type> ValueType;
uint32_t xfer = 0;
xfer += prot->serializedSizeMapBegin(
Cpp2Ops<KeyType>::thriftType(),
Expand Down

0 comments on commit a1c7a83

Please sign in to comment.