Skip to content

Commit 8da58da

Browse files
authored
chore: perfectly forward all make_iterator args (pybind#3980)
* Perfectly forward all make_iterator args * Try emplace back
1 parent 748ae22 commit 8da58da

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

include/pybind11/pybind11.h

+15-9
Original file line numberDiff line numberDiff line change
@@ -2333,7 +2333,7 @@ template <typename Access,
23332333
typename Sentinel,
23342334
typename ValueType,
23352335
typename... Extra>
2336-
iterator make_iterator_impl(Iterator first, Sentinel last, Extra &&...extra) {
2336+
iterator make_iterator_impl(Iterator &&first, Sentinel &&last, Extra &&...extra) {
23372337
using state = detail::iterator_state<Access, Policy, Iterator, Sentinel, ValueType, Extra...>;
23382338
// TODO: state captures only the types of Extra, not the values
23392339

@@ -2359,7 +2359,7 @@ iterator make_iterator_impl(Iterator first, Sentinel last, Extra &&...extra) {
23592359
Policy);
23602360
}
23612361

2362-
return cast(state{first, last, true});
2362+
return cast(state{std::forward<Iterator>(first), std::forward<Sentinel>(last), true});
23632363
}
23642364

23652365
PYBIND11_NAMESPACE_END(detail)
@@ -2370,13 +2370,15 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
23702370
typename Sentinel,
23712371
typename ValueType = typename detail::iterator_access<Iterator>::result_type,
23722372
typename... Extra>
2373-
iterator make_iterator(Iterator first, Sentinel last, Extra &&...extra) {
2373+
iterator make_iterator(Iterator &&first, Sentinel &&last, Extra &&...extra) {
23742374
return detail::make_iterator_impl<detail::iterator_access<Iterator>,
23752375
Policy,
23762376
Iterator,
23772377
Sentinel,
23782378
ValueType,
2379-
Extra...>(first, last, std::forward<Extra>(extra)...);
2379+
Extra...>(std::forward<Iterator>(first),
2380+
std::forward<Sentinel>(last),
2381+
std::forward<Extra>(extra)...);
23802382
}
23812383

23822384
/// Makes a python iterator over the keys (`.first`) of a iterator over pairs from a
@@ -2386,13 +2388,15 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
23862388
typename Sentinel,
23872389
typename KeyType = typename detail::iterator_key_access<Iterator>::result_type,
23882390
typename... Extra>
2389-
iterator make_key_iterator(Iterator first, Sentinel last, Extra &&...extra) {
2391+
iterator make_key_iterator(Iterator &&first, Sentinel &&last, Extra &&...extra) {
23902392
return detail::make_iterator_impl<detail::iterator_key_access<Iterator>,
23912393
Policy,
23922394
Iterator,
23932395
Sentinel,
23942396
KeyType,
2395-
Extra...>(first, last, std::forward<Extra>(extra)...);
2397+
Extra...>(std::forward<Iterator>(first),
2398+
std::forward<Sentinel>(last),
2399+
std::forward<Extra>(extra)...);
23962400
}
23972401

23982402
/// Makes a python iterator over the values (`.second`) of a iterator over pairs from a
@@ -2402,13 +2406,15 @@ template <return_value_policy Policy = return_value_policy::reference_internal,
24022406
typename Sentinel,
24032407
typename ValueType = typename detail::iterator_value_access<Iterator>::result_type,
24042408
typename... Extra>
2405-
iterator make_value_iterator(Iterator first, Sentinel last, Extra &&...extra) {
2409+
iterator make_value_iterator(Iterator &&first, Sentinel &&last, Extra &&...extra) {
24062410
return detail::make_iterator_impl<detail::iterator_value_access<Iterator>,
24072411
Policy,
24082412
Iterator,
24092413
Sentinel,
24102414
ValueType,
2411-
Extra...>(first, last, std::forward<Extra>(extra)...);
2415+
Extra...>(std::forward<Iterator>(first),
2416+
std::forward<Sentinel>(last),
2417+
std::forward<Extra>(extra)...);
24122418
}
24132419

24142420
/// Makes an iterator over values of an stl container or other container supporting
@@ -2467,7 +2473,7 @@ void implicitly_convertible() {
24672473
};
24682474

24692475
if (auto *tinfo = detail::get_type_info(typeid(OutputType))) {
2470-
tinfo->implicit_conversions.push_back(implicit_caster);
2476+
tinfo->implicit_conversions.emplace_back(std::move(implicit_caster));
24712477
} else {
24722478
pybind11_fail("implicitly_convertible: Unable to find type " + type_id<OutputType>());
24732479
}

0 commit comments

Comments
 (0)