Skip to content

Commit 73484df

Browse files
committed
fix issue #70
1 parent cb7e04c commit 73484df

File tree

3 files changed

+29
-4
lines changed

3 files changed

+29
-4
lines changed

examples/makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ CXXFLAGS = -O2 -std=c++11 -I..
22
CXXFLAGS += -Wall -pedantic -Wextra
33
SPP_DEPS_1 = spp.h spp_utils.h spp_dlalloc.h spp_traits.h spp_config.h
44
SPP_DEPS = $(addprefix ../sparsepp/,$(SPP_DEPS_1))
5-
TARGETS = emplace hash_std serialize_file serialize_stream serialize_large
5+
TARGETS = emplace piecewise hash_std serialize_file serialize_stream serialize_large
66

77
ifeq ($(OS),Windows_NT)
88
LDFLAGS = -lpsapi

examples/piecewise.cc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#include <unordered_map>
2+
#include <string>
3+
#include <iostream>
4+
#include <sparsepp/spp.h>
5+
6+
#include <sstream>
7+
8+
int main()
9+
{
10+
using StringPtr = std::unique_ptr<std::string>;
11+
12+
#if 1
13+
using StringPtrContainer = spp::sparse_hash_map<StringPtr, StringPtr>;
14+
#else
15+
using StringPtrContainer = std::unordered_map<StringPtr, StringPtr>;
16+
#endif
17+
18+
StringPtrContainer c;
19+
20+
c.emplace(std::piecewise_construct,
21+
std::forward_as_tuple(new std::string{ "key" }),
22+
std::forward_as_tuple(new std::string{ "value" }));
23+
}
24+

sparsepp/spp.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,7 @@ class sparsegroup
10641064
// T can be std::pair<const K, V>, but sometime we need to cast to a mutable type
10651065
// ------------------------------------------------------------------------------
10661066
typedef typename spp_::cvt<T>::type mutable_value_type;
1067+
typedef mutable_value_type & mutable_reference;
10671068
typedef mutable_value_type * mutable_pointer;
10681069
typedef const mutable_value_type * const_mutable_pointer;
10691070

@@ -1332,9 +1333,9 @@ class sparsegroup
13321333
void _init_val(mutable_value_type *p, reference val)
13331334
{
13341335
#if !defined(SPP_NO_CXX11_RVALUE_REFERENCES)
1335-
::new (p) value_type(std::move(val));
1336+
::new (p) value_type(std::move((mutable_reference)val));
13361337
#else
1337-
::new (p) value_type(val);
1338+
::new (p) value_type((mutable_reference)val);
13381339
#endif
13391340
}
13401341

@@ -1348,7 +1349,7 @@ class sparsegroup
13481349
void _set_val(value_type *p, reference val)
13491350
{
13501351
#if !defined(SPP_NO_CXX11_RVALUE_REFERENCES)
1351-
*(mutable_pointer)p = std::move(val);
1352+
*(mutable_pointer)p = std::move((mutable_reference)val);
13521353
#else
13531354
using std::swap;
13541355
swap(*(mutable_pointer)p, *(mutable_pointer)&val);

0 commit comments

Comments
 (0)