Created
March 16, 2013 23:37
-
-
Save biot023/5178831 to your computer and use it in GitHub Desktop.
Concept / copy-constructor issues
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
lib/nnet/include/nnet/wrapped_stack.h:22:17: error: no member named 'size' in 'nnet::WrappedStack<int>' | |
__stack.size(); // TODO -- DELETE THIS LINE, FOR TESTING ONLY. | |
~~~~~~~ ^ | |
lib/nnet/include/nnet/wrapped_stack.h:37:49: note: in instantiation of member function 'nnet::wrapped_stack_t<nnet::WrappedStack<int>, int>::push' requested here | |
WrappedStack( S &stack ) : __stack( new wrapped_stack_t<S, T>( stack ) ) {} | |
^ | |
/opt/local/libexec/llvm-3.2/bin/../lib/c++/v1/memory:1681:31: note: in instantiation of function template specialization 'nnet::WrappedStack<int>::WrappedStack<nnet::WrappedStack<int> >' requested here | |
::new((void*)__p) _Up(_VSTD::forward<_Args>(__args)...); | |
^ | |
/opt/local/libexec/llvm-3.2/bin/../lib/c++/v1/memory:1608:18: note: in instantiation of function template specialization 'std::__1::allocator<nnet::WrappedStack<int> >::construct<nnet::WrappedStack<int>, | |
nnet::WrappedStack<int> &>' requested here | |
{__a.construct(__p, _VSTD::forward<_Args>(__args)...);} | |
^ | |
/opt/local/libexec/llvm-3.2/bin/../lib/c++/v1/memory:1492:14: note: in instantiation of function template specialization 'std::__1::allocator_traits<std::__1::allocator<nnet::WrappedStack<int> > | |
>::__construct<nnet::WrappedStack<int>, nnet::WrappedStack<int> &>' requested here | |
{__construct(__has_construct<allocator_type, pointer, _Args...>(), | |
^ | |
/opt/local/libexec/llvm-3.2/bin/../lib/c++/v1/vector:933:25: note: in instantiation of function template specialization 'std::__1::allocator_traits<std::__1::allocator<nnet::WrappedStack<int> > | |
>::construct<nnet::WrappedStack<int>, nnet::WrappedStack<int> &>' requested here | |
__alloc_traits::construct(__a, _VSTD::__to_raw_pointer(this->__end_), *__first); | |
^ | |
/opt/local/libexec/llvm-3.2/bin/../lib/c++/v1/vector:1100:9: note: in instantiation of function template specialization 'std::__1::vector<nnet::WrappedStack<int>, | |
std::__1::allocator<nnet::WrappedStack<int> > >::__construct_at_end<nnet::WrappedStack<int> *>' requested here | |
__construct_at_end(__x.__begin_, __x.__end_); | |
^ | |
test/nnet/exec_test.cpp:34:38: note: in instantiation of member function 'std::__1::vector<nnet::WrappedStack<int>, std::__1::allocator<nnet::WrappedStack<int> > >::vector' requested here | |
vector<stack_t> __tmp_stacks = vector<stack_t>( __stacks ); | |
^ | |
1 error generated. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "wrapped_stack.h" | |
using stack_t = nnet::WrappedStack<int>; | |
deque<int> __base_stack = { 0, 1, 2, 3, 4 }; | |
stack<int> __stack = stack<int>( __base_stack ); | |
vector<stack_t> __stacks = { stack_t( __stack ) }; | |
vector<stack_t> __tmp_stacks = vector<stack_t>( __stacks ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <memory> | |
namespace nnet { | |
using namespace std; | |
template <typename T> | |
struct wrapped_stack_concept_t | |
{ | |
public: | |
virtual ~wrapped_stack_concept_t() {} | |
virtual void push( const T & ) = 0; | |
}; | |
template <typename S, typename T> | |
class wrapped_stack_t : public wrapped_stack_concept_t<T> | |
{ | |
public: | |
wrapped_stack_t( S &stack ) : __stack( stack ) {} | |
virtual void push( const T & val ) | |
{ | |
__stack.size(); // TODO -- DELETE THIS LINE, FOR TESTING ONLY. | |
__stack.push( val ); | |
} | |
private: | |
S &__stack; | |
}; | |
template <typename T> | |
class WrappedStack | |
{ | |
public: | |
WrappedStack() = default; | |
WrappedStack( const WrappedStack &other ) : __stack( other.__stack ) {} | |
WrappedStack( WrappedStack &&other ) : __stack( other.__stack ) {} | |
template <typename S> | |
WrappedStack( S &stack ) : __stack( new wrapped_stack_t<S, T>( stack ) ) {} | |
WrappedStack & operator= ( const WrappedStack &other ) { | |
__stack = other.__stack; return *this; | |
} | |
void push( const T &val ) { __stack->push( val ); } | |
private: | |
shared_ptr<wrapped_stack_concept_t<T>> __stack; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment