Why does this code involving boost::transform_iterator with a non-movable type not work? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Creating std::vector of nonmovable typeWhat does the C++ standard state the size of int, long type to be?defining < operator for map of list iteratorsWhy does changing 0.1f to 0 slow down performance by 10x?error while working with boost::sregex_token_iteratorWhy can I not move unique_ptr from a set to a function argument using an iterator?Why can I not call reserve on a vector of const elements?Xcode 5.1.1 and BoostUsing my custom iterator with stl algorithmsArray of std::vector's doesn't workWhy does “using namespace” try to instantiate templates in that namespace for MSVC
Do jazz musicians improvise on the parent scale in addition to the chord-scales?
Do square wave exist?
Has negative voting ever been officially implemented in elections, or seriously proposed, or even studied?
When a candle burns, why does the top of wick glow if bottom of flame is hottest?
What does this Jacques Hadamard quote mean?
Does classifying an integer as a discrete log require it be part of a multiplicative group?
Should I use a zero-interest credit card for a large one-time purchase?
Closed form of recurrent arithmetic series summation
Is it ethical to give a final exam after the professor has quit before teaching the remaining chapters of the course?
Dating a Former Employee
Is safe to use va_start macro with this as parameter?
How to show element name in portuguese using elements package?
Fundamental Solution of the Pell Equation
Significance of Cersei's obsession with elephants?
Would "destroying" Wurmcoil Engine prevent its tokens from being created?
How do I find out the mythology and history of my Fortress?
Can melee weapons be used to deliver Contact Poisons?
Is the Standard Deduction better than Itemized when both are the same amount?
How does the math work when buying airline miles?
How can I use the Python library networkx from Mathematica?
Do wooden building fires get hotter than 600°C?
Integration Help
What causes the direction of lightning flashes?
How to convince students of the implication truth values?
Why does this code involving boost::transform_iterator with a non-movable type not work?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern)
Data science time! April 2019 and salary with experience
The Ask Question Wizard is Live!Creating std::vector of nonmovable typeWhat does the C++ standard state the size of int, long type to be?defining < operator for map of list iteratorsWhy does changing 0.1f to 0 slow down performance by 10x?error while working with boost::sregex_token_iteratorWhy can I not move unique_ptr from a set to a function argument using an iterator?Why can I not call reserve on a vector of const elements?Xcode 5.1.1 and BoostUsing my custom iterator with stl algorithmsArray of std::vector's doesn't workWhy does “using namespace” try to instantiate templates in that namespace for MSVC
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
This code was inspired by another question on Stack Overflow a few days ago. It attempts to use a transform iterator to construct a std::vector containing a non-movable type.
#include <cstdio>
#include <iterator>
#include <vector>
#define BOOST_RESULT_OF_USE_DECLTYPE
#include <boost/iterator/transform_iterator.hpp>
struct NonMovable
NonMovable(const NonMovable&) = delete;
void operator=(const NonMovable&) = delete;
NonMovable(NonMovable&&) = delete; // redundant
void operator=(NonMovable&&) = delete; // redundant
NonMovable(int x, int y) : x(x), y(y)
int x;
int y;
;
int main(int argc, char* argv[])
std::vector<int> args = 1, 2, 3, 4;
int additional_arg = 5;
auto fun = [&additional_arg](auto arg) return NonMovable(arg, additional_arg); ;
std::vector<NonMovable> v(boost::make_transform_iterator(args.begin(), fun),
boost::make_transform_iterator(args.end(), fun));
for (const auto& item : v)
printf("%d %dn", item.x, item.y);
Unfortunately, this code doesn't compile (https://wandbox.org/permlink/20xMUsCBUg44YmXC). The error message from Clang mentions that the std::vector range constructor is disabled because:
no type named 'reference' in 'std::__1::iterator_traits<boost::iterators::transform_iterator<(lambda at prog.cc:22:16), std::__1::__wrap_iter<int *>, boost::iterators::use_default, boost::iterators::use_default> >'
But I can't see any reason why this iterator_traits specialization should not have a member named reference.
c++ iterator boost-iterators
add a comment |
This code was inspired by another question on Stack Overflow a few days ago. It attempts to use a transform iterator to construct a std::vector containing a non-movable type.
#include <cstdio>
#include <iterator>
#include <vector>
#define BOOST_RESULT_OF_USE_DECLTYPE
#include <boost/iterator/transform_iterator.hpp>
struct NonMovable
NonMovable(const NonMovable&) = delete;
void operator=(const NonMovable&) = delete;
NonMovable(NonMovable&&) = delete; // redundant
void operator=(NonMovable&&) = delete; // redundant
NonMovable(int x, int y) : x(x), y(y)
int x;
int y;
;
int main(int argc, char* argv[])
std::vector<int> args = 1, 2, 3, 4;
int additional_arg = 5;
auto fun = [&additional_arg](auto arg) return NonMovable(arg, additional_arg); ;
std::vector<NonMovable> v(boost::make_transform_iterator(args.begin(), fun),
boost::make_transform_iterator(args.end(), fun));
for (const auto& item : v)
printf("%d %dn", item.x, item.y);
Unfortunately, this code doesn't compile (https://wandbox.org/permlink/20xMUsCBUg44YmXC). The error message from Clang mentions that the std::vector range constructor is disabled because:
no type named 'reference' in 'std::__1::iterator_traits<boost::iterators::transform_iterator<(lambda at prog.cc:22:16), std::__1::__wrap_iter<int *>, boost::iterators::use_default, boost::iterators::use_default> >'
But I can't see any reason why this iterator_traits specialization should not have a member named reference.
c++ iterator boost-iterators
Not movable, not copyable, nor assignable, I wouldn't expect vector to work with it either
– JVApen
Mar 8 at 18:52
See stackoverflow.com/questions/54953039/…
– R2RT
Mar 8 at 20:19
Could it be: github.com/llvm-mirror/libcxx/blob/master/include/iterator#L491 ?
– Jeff Garrett
Mar 8 at 20:30
It seemsmake_transform_iteratorrequiresfunto be assignable. How can that be? A lambda is never assignable right?
– rustyx
Mar 8 at 21:51
add a comment |
This code was inspired by another question on Stack Overflow a few days ago. It attempts to use a transform iterator to construct a std::vector containing a non-movable type.
#include <cstdio>
#include <iterator>
#include <vector>
#define BOOST_RESULT_OF_USE_DECLTYPE
#include <boost/iterator/transform_iterator.hpp>
struct NonMovable
NonMovable(const NonMovable&) = delete;
void operator=(const NonMovable&) = delete;
NonMovable(NonMovable&&) = delete; // redundant
void operator=(NonMovable&&) = delete; // redundant
NonMovable(int x, int y) : x(x), y(y)
int x;
int y;
;
int main(int argc, char* argv[])
std::vector<int> args = 1, 2, 3, 4;
int additional_arg = 5;
auto fun = [&additional_arg](auto arg) return NonMovable(arg, additional_arg); ;
std::vector<NonMovable> v(boost::make_transform_iterator(args.begin(), fun),
boost::make_transform_iterator(args.end(), fun));
for (const auto& item : v)
printf("%d %dn", item.x, item.y);
Unfortunately, this code doesn't compile (https://wandbox.org/permlink/20xMUsCBUg44YmXC). The error message from Clang mentions that the std::vector range constructor is disabled because:
no type named 'reference' in 'std::__1::iterator_traits<boost::iterators::transform_iterator<(lambda at prog.cc:22:16), std::__1::__wrap_iter<int *>, boost::iterators::use_default, boost::iterators::use_default> >'
But I can't see any reason why this iterator_traits specialization should not have a member named reference.
c++ iterator boost-iterators
This code was inspired by another question on Stack Overflow a few days ago. It attempts to use a transform iterator to construct a std::vector containing a non-movable type.
#include <cstdio>
#include <iterator>
#include <vector>
#define BOOST_RESULT_OF_USE_DECLTYPE
#include <boost/iterator/transform_iterator.hpp>
struct NonMovable
NonMovable(const NonMovable&) = delete;
void operator=(const NonMovable&) = delete;
NonMovable(NonMovable&&) = delete; // redundant
void operator=(NonMovable&&) = delete; // redundant
NonMovable(int x, int y) : x(x), y(y)
int x;
int y;
;
int main(int argc, char* argv[])
std::vector<int> args = 1, 2, 3, 4;
int additional_arg = 5;
auto fun = [&additional_arg](auto arg) return NonMovable(arg, additional_arg); ;
std::vector<NonMovable> v(boost::make_transform_iterator(args.begin(), fun),
boost::make_transform_iterator(args.end(), fun));
for (const auto& item : v)
printf("%d %dn", item.x, item.y);
Unfortunately, this code doesn't compile (https://wandbox.org/permlink/20xMUsCBUg44YmXC). The error message from Clang mentions that the std::vector range constructor is disabled because:
no type named 'reference' in 'std::__1::iterator_traits<boost::iterators::transform_iterator<(lambda at prog.cc:22:16), std::__1::__wrap_iter<int *>, boost::iterators::use_default, boost::iterators::use_default> >'
But I can't see any reason why this iterator_traits specialization should not have a member named reference.
c++ iterator boost-iterators
c++ iterator boost-iterators
asked Mar 8 at 18:48
BrianBrian
66.8k799191
66.8k799191
Not movable, not copyable, nor assignable, I wouldn't expect vector to work with it either
– JVApen
Mar 8 at 18:52
See stackoverflow.com/questions/54953039/…
– R2RT
Mar 8 at 20:19
Could it be: github.com/llvm-mirror/libcxx/blob/master/include/iterator#L491 ?
– Jeff Garrett
Mar 8 at 20:30
It seemsmake_transform_iteratorrequiresfunto be assignable. How can that be? A lambda is never assignable right?
– rustyx
Mar 8 at 21:51
add a comment |
Not movable, not copyable, nor assignable, I wouldn't expect vector to work with it either
– JVApen
Mar 8 at 18:52
See stackoverflow.com/questions/54953039/…
– R2RT
Mar 8 at 20:19
Could it be: github.com/llvm-mirror/libcxx/blob/master/include/iterator#L491 ?
– Jeff Garrett
Mar 8 at 20:30
It seemsmake_transform_iteratorrequiresfunto be assignable. How can that be? A lambda is never assignable right?
– rustyx
Mar 8 at 21:51
Not movable, not copyable, nor assignable, I wouldn't expect vector to work with it either
– JVApen
Mar 8 at 18:52
Not movable, not copyable, nor assignable, I wouldn't expect vector to work with it either
– JVApen
Mar 8 at 18:52
See stackoverflow.com/questions/54953039/…
– R2RT
Mar 8 at 20:19
See stackoverflow.com/questions/54953039/…
– R2RT
Mar 8 at 20:19
Could it be: github.com/llvm-mirror/libcxx/blob/master/include/iterator#L491 ?
– Jeff Garrett
Mar 8 at 20:30
Could it be: github.com/llvm-mirror/libcxx/blob/master/include/iterator#L491 ?
– Jeff Garrett
Mar 8 at 20:30
It seems
make_transform_iterator requires fun to be assignable. How can that be? A lambda is never assignable right?– rustyx
Mar 8 at 21:51
It seems
make_transform_iterator requires fun to be assignable. How can that be? A lambda is never assignable right?– rustyx
Mar 8 at 21:51
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069260%2fwhy-does-this-code-involving-boosttransform-iterator-with-a-non-movable-type-n%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55069260%2fwhy-does-this-code-involving-boosttransform-iterator-with-a-non-movable-type-n%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Not movable, not copyable, nor assignable, I wouldn't expect vector to work with it either
– JVApen
Mar 8 at 18:52
See stackoverflow.com/questions/54953039/…
– R2RT
Mar 8 at 20:19
Could it be: github.com/llvm-mirror/libcxx/blob/master/include/iterator#L491 ?
– Jeff Garrett
Mar 8 at 20:30
It seems
make_transform_iteratorrequiresfunto be assignable. How can that be? A lambda is never assignable right?– rustyx
Mar 8 at 21:51