Multiple overloads of __compressed_pair error implementing unordered_set - c++

I'm trying to implement an unordered_set in my bfs algorithm, but it gives me this errors:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2412:40:
error: multiple overloads
of '__compressed_pair' instantiate to the same signature 'void (_T2_param)' (aka 'void (int)')
_LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T2_param __t2)
^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/__hash_table:969:59:
note: in instantiation
of template class 'std::__1::__compressed_pair >' requested here
__compressed_pair __p2_;
^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/unordered_set:353:13:
note: in
instantiation of template class 'std::__1::__hash_table, std::__1::equal_to, std::__1::allocator
'
requested here
__table __table_;
^ AICharques.cc:47:21: note: in instantiation of template class 'std::__1::unordered_set,
std::__1::equal_to,
std::__1::allocator >' requested here
unordered_set visited;
^ /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2410:40:
note: previous declaration
is here
_LIBCPP_INLINE_VISIBILITY explicit __compressed_pair(_T1_param __t1)
And this is my code:
void radar_bfs(Pos actualPos){
queue<Pos> frontier;
frontier.push(actualPos);
unordered_set<Pos> visited;
visited.insert(actualPos);
while(!frontier.empty()){
auto current = frontier.front();
frontier.pop();
for(auto next : neighbors(current)) {
if(not visited.count(next)){
frontier.push(next);
visited.insert(next);
}
}
}
}
Pos is a struct that contains two ints, i and j.(position in a board).
When i use just a set instead, the errors disappear.

Related

How to pass an object function as a template argument

bool HuffmanNode::Compare::operator()(const HuffmanNode &n1, const HuffmanNode &n2) const
{
if (n1.frequency == n2.frequency) {
return lessThan ? n1.character < n2.character : n1.character >= n2.character;
} else {
return lessThan ? n1.frequency < n2.frequency : n1.frequency >= n2.frequency;
}
}
bool HuffmanNode::Compare::operator()(const HuffmanNode *n1, const HuffmanNode *n2) const
{
return operator()(*n1, *n2);
}
Here I have a compare function from a compare object that is within another object (HuffmanNode).
I want to pass the compare function to another object through a template:
HeapQueue<HuffmanNode, HuffmanNode::Compare> queue;
This doesn't seem to work and I've even tried using the operator function.
What is the proper format for this? Thanks.
Here is my compiler error
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1826:31: error:
no matching constructor for initialization of 'HuffmanNode'
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1718:18: note:
in instantiation of function template specialization
'std::__1::allocator<HuffmanNode>::construct<HuffmanNode>' requested here
{__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1561:14: note:
in instantiation of function template specialization
'std::__1::allocator_traits<std::__1::allocator<HuffmanNode>
>::__construct<HuffmanNode>' requested here
{__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:1030:25: note:
in instantiation of function template specialization
'std::__1::allocator_traits<std::__1::allocator<HuffmanNode>
>::construct<HuffmanNode>' requested here
__alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:1121:9: note:
in instantiation of member function 'std::__1::vector<HuffmanNode,
std::__1::allocator<HuffmanNode> >::__construct_at_end' requested here
__construct_at_end(__n);
^
./HeapQueue.hpp:25:26: note: in instantiation of member function
'std::__1::vector<HuffmanNode, std::__1::allocator<HuffmanNode> >::vector'
requested here
VectorCompleteTree() : V(1) {}
^
./HeapQueue.hpp:46:7: note: in instantiation of member function
'VectorCompleteTree<HuffmanNode>::VectorCompleteTree' requested here
class HeapQueue
^
./HuffmanBase.hpp:8:7: note: candidate constructor (the implicit copy
constructor) not viable: requires 1 argument, but 0 were provided
class HuffmanNode {
^
./HuffmanBase.hpp:8:7: note: candidate constructor (the implicit move
constructor) not viable: requires 1 argument, but 0 were provided
./HuffmanBase.hpp:11:3: note: candidate constructor not viable: requires 2
arguments, but 0 were provided
HuffmanNode(char c, size_t f) : HuffmanNode(c, f, nullptr, nullptr, nu...
^
./HuffmanBase.hpp:10:3: note: candidate constructor not viable: requires 5
arguments, but 0 were provided
HuffmanNode(char c, size_t f, HuffmanNode *p, HuffmanNode *l, HuffmanN...
^
1 error generated.
Starting from the bottom of the error message, the compiler is trying to do this HuffmanNode{} but failing because HuffmanNode doesn't have a default constructor. The key here is but 0 were provided.
./HuffmanBase.hpp:8:7: note: candidate constructor (the implicit copy
constructor) not viable: requires 1 argument, but 0 were provided
class HuffmanNode {
^
./HuffmanBase.hpp:8:7: note: candidate constructor (the implicit move
constructor) not viable: requires 1 argument, but 0 were provided
./HuffmanBase.hpp:11:3: note: candidate constructor not viable: requires 2
arguments, but 0 were provided
HuffmanNode(char c, size_t f) : HuffmanNode(c, f, nullptr, nullptr, nu...
^
./HuffmanBase.hpp:10:3: note: candidate constructor not viable: requires 5
arguments, but 0 were provided
HuffmanNode(char c, size_t f, HuffmanNode *p, HuffmanNode *l, HuffmanN...
^
The default constructor of HeapQueue is invoking the default constructor of VectorCompleteTree<HuffmanNode>.
./HeapQueue.hpp:46:7: note: in instantiation of member function
'VectorCompleteTree<HuffmanNode>::VectorCompleteTree' requested here
class HeapQueue
The default constructor of VectorCompleteTree<HuffmanNode> is constructing a std::vector<HuffmanNode> with one element. This one element needs to be default constructed.
./HeapQueue.hpp:25:26: note: in instantiation of member function
'std::__1::vector<HuffmanNode, std::__1::allocator<HuffmanNode> >::vector'
requested here
VectorCompleteTree() : V(1) {}
std::vector<HuffmanNode> is trying to default construct a HuffmanNode but can't.
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1826:31: error:
no matching constructor for initialization of 'HuffmanNode'
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1718:18: note:
in instantiation of function template specialization
'std::__1::allocator<HuffmanNode>::construct<HuffmanNode>' requested here
{__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/memory:1561:14: note:
in instantiation of function template specialization
'std::__1::allocator_traits<std::__1::allocator<HuffmanNode>
>::__construct<HuffmanNode>' requested here
{__construct(__has_construct<allocator_type, _Tp*, _Args...>(),
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:1030:25: note:
in instantiation of function template specialization
'std::__1::allocator_traits<std::__1::allocator<HuffmanNode>
>::construct<HuffmanNode>' requested here
__alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_));
^
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/vector:1121:9: note:
in instantiation of member function 'std::__1::vector<HuffmanNode,
std::__1::allocator<HuffmanNode> >::__construct_at_end' requested here
__construct_at_end(__n);
It's all there in the error message! The simple solution would be do give HuffmanNode a default constructor.

Clang AST - convert pointer to reference? [C++]

I'm trying to store my methodDecl nodes in a map within RecursiveASTVisitor
std::map<std::string, ObjCMethodDecl> ObjCMethodsMap;
Currently I'm storing it like this
virtual bool HandleTopLevelDecl (DeclGroupRef DG) {
for (DeclGroupRef::iterator i = DG.begin(), e = DG.end(); i != e; ++i) {
Decl *D = *i;
if (ObjCMethodDecl *methodDecl = dyn_cast<ObjCMethodDecl>(D)) {
std::string methodName = methodDecl->getNameAsString();
ObjCMethodsMap[methodName] = ObjCMethodDecl(*methodDecl);
}
}
}
And when I'm trying to use it, I do this
ObjCMethodDecl methodDecl = ObjCMethodsMap["textFieldShouldReturn:"];
Visitor->TraverseDecl(&methodDecl);
This may be more of a C++ question, but am I doing anything wrongly in my way of storing it in reference?
Below is the compilation error message I'm getting. I'm not sure what does it say now because it is referencing to something not within my code and doesn't tell me which line it came from. That's why I thought maybe I did something wrong in C++
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1645:31: error: no matching constructor for initialization of 'clang::ObjCMethodDecl'
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1572:18: note: in instantiation of function template specialization 'std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char>, clang::ObjCMethodDecl>, void *> >::construct<clang::ObjCMethodDecl>' requested here
{__a.construct(__p, _VSTD::forward<_Args>(__args)...);}
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:1453:14: note: in instantiation of function template specialization 'std::__1::allocator_traits<std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char>, clang::ObjCMethodDecl>, void *> > >::__construct<clang::ObjCMethodDecl>' requested here
{__construct(__has_construct<allocator_type, pointer, _Args...>(),
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/map:1366:20: note: in instantiation of function template specialization 'std::__1::allocator_traits<std::__1::allocator<std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char>, clang::ObjCMethodDecl>, void *> > >::construct<clang::ObjCMethodDecl>' requested here
__node_traits::construct(__na, _VSTD::addressof(__h->__value_.__cc.second));
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/map:1380:29: note: in instantiation of member function 'std::__1::map<std::__1::basic_string<char>, clang::ObjCMethodDecl, std::__1::less<std::__1::basic_string<char> >, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char>, clang::ObjCMethodDecl> > >::__construct_node_with_key' requested here
__node_holder __h = __construct_node_with_key(__k);
^
/Users/jeremy/Desktop/clang-llvm/llvm/tools/clang/tools/extra/myASTChecker/MyASTChecker.cpp:272:55: note: in instantiation of member function 'std::__1::map<std::__1::basic_string<char>, clang::ObjCMethodDecl, std::__1::less<std::__1::basic_string<char> >, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char>, clang::ObjCMethodDecl> > >::operator[]' requested here
ObjCMethodDecl methodDecl = ObjCMethodsMap[selectorName];
^
/Users/jeremy/Desktop/clang-llvm/llvm/tools/clang/include/clang/AST/DeclObjC.h:113:7: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 0 were provided
class ObjCMethodDecl : public NamedDecl, public DeclContext {
^
/Users/jeremy/Desktop/clang-llvm/llvm/tools/clang/include/clang/AST/DeclObjC.h:113:7: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 0 were provided
/Users/jeremy/Desktop/clang-llvm/llvm/tools/clang/include/clang/AST/DeclObjC.h:226:3: note: candidate constructor not viable: requires at least 6 arguments, but 0 were provided
ObjCMethodDecl(SourceLocation beginLoc, SourceLocation endLoc,

cpprest/pplx : call to implicitly-deleted default constructor of '_ResultHolder<SomeObj>'

I am currently using the cpprest API found at https://casablanca.codeplex.com/ for a simple RESTful API project.
This popular library uses Microsoft's PPLX framework to facilitate the async tasks.
I am currently encountering an issue in which code does not compile when a function returns an object of type pplx::task<SomeObj> and SomeObj has no default constructor. My understanding is that this code should be a valid as no default objects should be created.
Is there an error in my code or is this a bug?
Example Code:
#include <vector>
#include <string>
#include <cpprest/http_client.h>
class SomeSubObj {
public:
int a,b,c;
SomeSubObj(int a, int b, int c): a(a), b(b), c(c){}
};
class SomeObj {
public:
std::vector<SomeSubObj> subObjs;
SomeObj(std::string json){
// Populate from JSON...
subObjs.push_back(SomeSubObj(1,1,1));
subObjs.push_back(SomeSubObj(2,2,2));
subObjs.push_back(SomeSubObj(3,3,3));
}
};
pplx::task<SomeObj> doSomething(){
return pplx::task<std::string>([]() {
// Make a call out and get some json...
return std::string("{...}");
}).then([](std::string x) {
// Return a transformed object
return SomeObj("...");
});
}
int main()
{
doSomething();
return 0;
}
I am currently receiving the following output:
g++ -std=c++0x -Iboost_thread-mt -Iboost_atomic -Iboost_system -Icpprest -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Bug.d" -MT"src/Bug.d" -o "src/Bug.o" "../src/Bug.cpp"
In file included from ../src/Bug.cpp:4:
In file included from /usr/local/include/cpprest/http_client.h:44:
/usr/local/include/pplx/pplxtasks.h:2404:9: error: call to implicitly-deleted default constructor of '_ResultHolder<SomeObj>'
_Task_impl(_CancellationTokenState * _Ct, scheduler_ptr _Scheduler_arg)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2096:15: note: in instantiation of member function 'pplx::details::_Task_impl<SomeObj>::_Task_impl' requested here
__second_(_VSTD::forward<_Args2>(get<_I2>(__second_args))...)
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:2359:15: note: in instantiation of function template specialization 'std::__1::__libcpp_compressed_pair_imp<std::__1::allocator<pplx::details::_Task_impl<SomeObj> >, pplx::details::_Task_impl<SomeObj>, 1>::__libcpp_compressed_pair_imp<std::__1::allocator<pplx::details::_Task_impl<SomeObj> > &, pplx::details::_CancellationTokenState *&, pplx::scheduler_ptr &, 0, 0, 1>' requested here
: base(__pc, _VSTD::move(__first_args), _VSTD::move(__second_args),
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:3697:16: note: in instantiation of function template specialization 'std::__1::__compressed_pair<std::__1::allocator<pplx::details::_Task_impl<SomeObj> >, pplx::details::_Task_impl<SomeObj> >::__compressed_pair<std::__1::allocator<pplx::details::_Task_impl<SomeObj> > &, pplx::details::_CancellationTokenState *&, pplx::scheduler_ptr &>' requested here
: __data_(piecewise_construct, _VSTD::forward_as_tuple(__a),
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4271:26: note: in instantiation of function template specialization 'std::__1::__shared_ptr_emplace<pplx::details::_Task_impl<SomeObj>, std::__1::allocator<pplx::details::_Task_impl<SomeObj> > >::__shared_ptr_emplace<pplx::details::_CancellationTokenState *&, pplx::scheduler_ptr &>' requested here
::new(__hold2.get()) _CntrlBlk(__a2, _VSTD::forward<_Args>(__args)...);
^
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/memory:4630:29: note: in instantiation of function template specialization 'std::__1::shared_ptr<pplx::details::_Task_impl<SomeObj> >::make_shared<pplx::details::_CancellationTokenState *&, pplx::scheduler_ptr &>' requested here
return shared_ptr<_Tp>::make_shared(_VSTD::forward<_Args>(__args)...);
^
/usr/local/include/pplx/pplxtasks.h:1429:103: note: (skipping 1 context in backtrace; use -ftemplate-backtrace-limit=0 to see all)
static _Type _Make(_CancellationTokenState * _Ct, scheduler_ptr _Scheduler_arg) { return std::make_shared<_Task_impl<_ReturnType>>(_Ct, _Scheduler_arg); }
^
/usr/local/include/pplx/pplxtasks.h:3623:52: note: in instantiation of member function 'pplx::details::_Task_ptr<SomeObj>::_Make' requested here
_M_Impl = details::_Task_ptr<_ReturnType>::_Make(_Ct, _Scheduler);
^
/usr/local/include/pplx/pplxtasks.h:4138:27: note: in instantiation of member function 'pplx::task<SomeObj>::_CreateImpl' requested here
_ContinuationTask._CreateImpl(_PTokenState, _Scheduler);
^
/usr/local/include/pplx/pplxtasks.h:4101:16: note: in instantiation of function template specialization 'pplx::task<std::__1::basic_string<char> >::_ThenImpl<std::__1::basic_string<char>, <lambda at ../src/Bug.cpp:27:10> >' requested here
return _ThenImpl<_InternalReturnType, _Function>(_Func, _PTokenState, _TaskOptions.get_continuation_context(), _Scheduler, _CreationStack);
^
/usr/local/include/pplx/pplxtasks.h:3424:16: note: in instantiation of function template specialization 'pplx::task<std::__1::basic_string<char> >::_ThenImpl<std::__1::basic_string<char>, <lambda at ../src/Bug.cpp:27:10> >' requested here
return _ThenImpl<_ReturnType, _Function>(_Func, _TaskOptions);
^
../src/Bug.cpp:27:5: note: in instantiation of function template specialization 'pplx::task<std::__1::basic_string<char> >::then<<lambda at ../src/Bug.cpp:27:10> >' requested here
}).then([](std::string x) {
^
/usr/local/include/pplx/pplxtasks.h:844:15: note: default constructor of '_ResultHolder<SomeObj>' is implicitly deleted because field '_Result' has no default constructor
_Type _Result;
^
1 error generated.
make: *** [src/Bug.o] Error 1

C++11 decltype: How to declare the type that a pointer points to?

I have the following code:
#include <memory>
int main()
{
int* a = new int(2);
std::unique_ptr<decltype(*a)> p(a);
}
which leads to these error message:
In file included from a.cpp:1:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/memory:81:
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/unique_ptr.h:138:14: error: '__test' declared as a pointer to a reference of type 'int &'
static _Tp* __test(...);
^
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/unique_ptr.h:146:35: note: in instantiation of member class 'std::unique_ptr<int &,
std::default_delete<int &> >::_Pointer' requested here
typedef std::tuple<typename _Pointer::type, _Dp> __tuple_type;
^
a.cpp:7:35: note: in instantiation of template class 'std::unique_ptr<int &, std::default_delete<int &> >' requested here
std::unique_ptr<decltype(*a)> p(a);
^
In file included from a.cpp:1:
In file included from /usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/memory:81:
/usr/bin/../lib64/gcc/x86_64-unknown-linux-gnu/4.9.2/../../../../include/c++/4.9.2/bits/unique_ptr.h:227:33: error: 'type name' declared as a pointer to a reference of type 'int &'
is_convertible<_Up*, _Tp*>, is_same<_Dp, default_delete<_Tp>>>>
^
a.cpp:7:35: note: in instantiation of template class 'std::unique_ptr<int &, std::default_delete<int &> >' requested here
std::unique_ptr<decltype(*a)> p(a);
^
2 errors generated.
I understand the reason is that the unique_ptr template expects type int, but decltype(*a) gives int&. In the case that int is a very long and complicated type, how can I make this code work with decltype?
Use std::decay_t. This is the conversion that is applied when you pass an argument to a function by value.
You can use a typedef inside a templated class and then use template specialisation, like this
template<typename T> struct unref {
typedef T raw;
};
template<typename T> struct unref<T&> {
typedef T raw;
};
int main() {
int* a = new int(2);
std::unique_ptr<unref<decltype(*a)>::raw> p(a);
}

std::packaged_task::reset example from http://www.cplusplus.com doesn't work

I tried to compile and run example of reset() function from http://www.cplusplus.com/reference/future/packaged_task/reset/:
$ cat task.cpp
// packaged_task::get_future
#include <iostream> // std::cout
#include <utility> // std::move
#include <future> // std::packaged_task, std::future
#include <thread> // std::thread
// a simple task:
int triple (int x) { return x*3; }
int main ()
{
std::packaged_task<int(int)> tsk (triple); // package task
std::future<int> fut = tsk.get_future();
std::thread (std::move(tsk),33).detach();
std::cout << "The triple of 33 is " << fut.get() << ".\n";
// re-use same task object:
tsk.reset();
fut = tsk.get_future();
std::thread(std::move(tsk),99).detach();
std::cout << "Thre triple of 99 is " << fut.get() << ".\n";
return 0;
}
but I got either compiler error or runtime error, depending on compiler used:
GCC:
$ g++ -o task -std=c++11 -I/opt/local/include task.cpp && ./task
The triple of 33 is 99.
terminate called after throwing an instance of 'std::future_error'
what(): No associated state
[1] 14850 abort ./task
CLANG:
$ clang++ -o task -std=c++11 -stdlib=libc++ -I/opt/local/include task.cpp && ./task
In file included from task.cpp:2:
In file included from /opt/local/libexec/llvm-3.4/bin/../include/c++/v1/iostream:38:
In file included from /opt/local/libexec/llvm-3.4/bin/../include/c++/v1/ios:216:
In file included from /opt/local/libexec/llvm-3.4/bin/../include/c++/v1/__locale:15:
In file included from /opt/local/libexec/llvm-3.4/bin/../include/c++/v1/string:439:
In file included from /opt/local/libexec/llvm-3.4/bin/../include/c++/v1/algorithm:627:
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/memory:1627:45: error: multiple overloads of 'address' instantiate to the same
signature 'const_pointer (const_reference) const noexcept'
_LIBCPP_INLINE_VISIBILITY const_pointer address(const_reference __x) const _NOEXCEPT
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/type_traits:922:38: note: in instantiation of template class
'std::__1::allocator<int (int)>' requested here
: public integral_constant<bool, __is_empty(_Tp)> {};
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/memory:1908:40: note: in instantiation of template class
'std::__1::is_empty<std::__1::allocator<int (int)> >' requested here
bool = is_empty<_T2>::value
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/memory:1930:44: note: in instantiation of default argument for
'__libcpp_compressed_pair_switch<int (int), std::__1::allocator<int (int)>, false, false>' required here
template <class _T1, class _T2, unsigned = __libcpp_compressed_pair_switch<_T1, _T2>::value>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/memory:2298:15: note: in instantiation of default argument for
'__libcpp_compressed_pair_imp<int (int), std::__1::allocator<int (int)> >' required here
: private __libcpp_compressed_pair_imp<_T1, _T2>
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/future:1770:36: note: in instantiation of template class
'std::__1::__compressed_pair<int (int), std::__1::allocator<int (int)> >' requested here
__compressed_pair<_Fp, _Alloc> __f_;
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/future:1877:9: note: in instantiation of template class
'std::__1::__packaged_task_func<int (int), std::__1::allocator<int (int)>, int (int)>' requested here
if (sizeof(_FF) <= sizeof(__buf_))
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/future:2026:45: note: in instantiation of function template specialization
'std::__1::__packaged_task_function<int (int)>::__packaged_task_function<int (&)(int)>' requested here
explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
^
task.cpp:12:32: note: in instantiation of function template specialization 'std::__1::packaged_task<int
(int)>::packaged_task<int (&)(int), void>' requested here
std::packaged_task<int(int)> tsk (triple); // package task
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/memory:1625:39: note: previous declaration is here
_LIBCPP_INLINE_VISIBILITY pointer address(reference __x) const _NOEXCEPT
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/memory:2121:9: error: data member instantiated with function type 'int (int)'
_T1 __first_;
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/memory:2298:15: note: in instantiation of template class
'std::__1::__libcpp_compressed_pair_imp<int (int), std::__1::allocator<int (int)>, 2>' requested here
: private __libcpp_compressed_pair_imp<_T1, _T2>
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/future:1770:36: note: in instantiation of template class
'std::__1::__compressed_pair<int (int), std::__1::allocator<int (int)> >' requested here
__compressed_pair<_Fp, _Alloc> __f_;
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/future:1877:9: note: in instantiation of template class
'std::__1::__packaged_task_func<int (int), std::__1::allocator<int (int)>, int (int)>' requested here
if (sizeof(_FF) <= sizeof(__buf_))
^
/opt/local/libexec/llvm-3.4/bin/../include/c++/v1/future:2026:45: note: in instantiation of function template specialization
'std::__1::__packaged_task_function<int (int)>::__packaged_task_function<int (&)(int)>' requested here
explicit packaged_task(_Fp&& __f) : __f_(_VSTD::forward<_Fp>(__f)) {}
^
task.cpp:12:32: note: in instantiation of function template specialization 'std::__1::packaged_task<int
(int)>::packaged_task<int (&)(int), void>' requested here
std::packaged_task<int(int)> tsk (triple); // package task
^
2 errors generated.
I'm using OSX Maverics and compilers:
$ g++ --version
g++ (MacPorts gcc48 4.8.2_0) 4.8.2
$ clang++ --version
clang version 3.4 (tags/RELEASE_34/final)
Target: x86_64-apple-darwin13.1.0
Thread model: posix
Could someone please help me?
GCC is correct:
std::thread (std::move(tsk),33).detach(); // 1
//...
tsk.reset(); // 2
After (1), tsk has no more state (per move constructor of packaged_task)
At (2), reset() is required to throw the no_state std::future_error
clang had a bug, as pointed out in the comments.