Well, I successfully built the test programme:
#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <iterator>
#include <algorithm>
int main()
{
using namespace boost::lambda;
typedef std::istream_iterator<int> in;
std::for_each(
in(std::cin), in(), std::cout << (_1 * 3) << " " );
}
but when I tried the one for boost::mpl::map, it barfed:
#include <boost/mpl/map.hpp>
#include <boost/mpl/assert.hpp>
int main()
{
using std::is_same;
using boost::mpl::at;
using boost::mpl::long_;
using boost::mpl::void_;
using boost::mpl::map;
using boost::mpl::pair;
//using namespace boost::mpl;
typedef map <
pair<int, unsigned>
, pair<char, unsigned char>
, pair<long_<5>, char[17]>
, pair < int[42], bool >
> m;
BOOST_MPL_ASSERT_RELATION(size<m>::value, == , 4);
BOOST_MPL_ASSERT_NOT((empty<m>));
BOOST_MPL_ASSERT((is_same< at<m, int>::type, unsigned >));
BOOST_MPL_ASSERT((is_same< at<m, long_<5> >::type, char[17] >));
BOOST_MPL_ASSERT((is_same< at<m, int[42]>::type, bool >));
BOOST_MPL_ASSERT((is_same< at<m, long>::type, void_ >));
return 0;
}
This is the compiler output:
1>------ Build started: Project: example, Configuration: Debug Win32 ------
1> example.cpp
1>c:\projects\example\example\example.cpp(22): error C2027: use of undefined type 'boost::mpl::size<m>'
1>c:\projects\example\example\example.cpp(22): error C2065: 'value' : undeclared identifier
1>c:\projects\example\example\example.cpp(22): error C2975: 'x' : invalid template argument for 'boost::mpl::assert_relation', expected compile-time constant expression
1> c:\boost_1_57_0\boost\mpl\assert.hpp(120) : see declaration of 'x'
1>c:\projects\example\example\example.cpp(22): error C2664: 'int boost::mpl::assertion_failed<0>(boost::mpl::assert<false>::type)' : cannot convert argument 1 from 'boost::mpl::failed ************boost::mpl::assert_relation<0,4,bool boost::mpl::operator ==(boost::mpl::failed,boost::mpl::failed)>::* ***********' to 'boost::mpl::assert<false>::type'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\boost_1_57_0\boost\mpl\assert.hpp(176): error C2027: use of undefined type 'boost::mpl::empty<m>'
1> c:\projects\example\example\example.cpp(23) : see reference to class template instantiation 'boost::mpl::assert_arg_pred<boost::mpl::empty<m>>' being compiled
1>c:\boost_1_57_0\boost\mpl\assert.hpp(176): error C2146: syntax error : missing ';' before identifier 'p_type'
1>c:\boost_1_57_0\boost\mpl\assert.hpp(176): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost_1_57_0\boost\mpl\assert.hpp(177): error C2653: 'p_type' : is not a class or namespace name
1>c:\boost_1_57_0\boost\mpl\assert.hpp(177): error C2065: 'value' : undeclared identifier
1>c:\boost_1_57_0\boost\mpl\assert.hpp(177): error C2975: 'unnamed-parameter' : invalid template argument for 'boost::mpl::assert_arg_pred_impl', expected compile-time constant expression
1> c:\boost_1_57_0\boost\mpl\assert.hpp(171) : see declaration of 'unnamed-parameter'
1>c:\boost_1_57_0\boost\mpl\assert.hpp(182): error C2027: use of undefined type 'boost::mpl::empty<m>'
1> c:\projects\example\example\example.cpp(23) : see reference to class template instantiation 'boost::mpl::assert_arg_pred_not<boost::mpl::empty<m>>' being compiled
1>c:\boost_1_57_0\boost\mpl\assert.hpp(182): error C2146: syntax error : missing ';' before identifier 'p_type'
1>c:\boost_1_57_0\boost\mpl\assert.hpp(182): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost_1_57_0\boost\mpl\assert.hpp(183): error C2653: 'p_type' : is not a class or namespace name
1>c:\boost_1_57_0\boost\mpl\assert.hpp(183): error C2065: 'value' : undeclared identifier
1>c:\boost_1_57_0\boost\mpl\assert.hpp(183): error C2057: expected constant expression
1>c:\boost_1_57_0\boost\mpl\assert.hpp(184): error C2975: 'unnamed-parameter' : invalid template argument for 'boost::mpl::assert_arg_pred_impl', expected compile-time constant expression
1> c:\boost_1_57_0\boost\mpl\assert.hpp(171) : see declaration of 'unnamed-parameter'
1>c:\projects\example\example\example.cpp(23): error C2668: 'boost::mpl::assert_not_arg' : ambiguous call to overloaded function
1> c:\boost_1_57_0\boost\mpl\assert.hpp(203): could be 'boost::mpl::assert<false> boost::mpl::assert_not_arg<boost::mpl::empty<m>>(void (__cdecl *)(Pred),int)'
1> with
1> [
1> Pred=boost::mpl::empty<m>
1> ]
1> c:\boost_1_57_0\boost\mpl\assert.hpp(194): or 'boost::mpl::failed ************boost::mpl::not_<boost::mpl::empty<m>>::* ***********boost::mpl::assert_not_arg<boost::mpl::empty<m>>(void (__cdecl *)(Pred),int)'
1> with
1> [
1> Pred=boost::mpl::empty<m>
1> ]
1> while trying to match the argument list '(void (__cdecl *)(boost::mpl::empty<m>), int)'
1>c:\projects\example\example\example.cpp(25): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Even doing the following:
#include <boost/mpl/map.hpp>
int main()
{
using std::is_same;
using boost::mpl::at;
using boost::mpl::long_;
using boost::mpl::map;
using boost::mpl::pair;
typedef map <
pair<int, unsigned>
, pair<char, unsigned char>
, pair<long_<5>, char[17]>
, pair < int[42], bool >
> m;
at<m, int>::type a;
return 0;
}
fails:
1>------ Build started: Project: example, Configuration: Debug Win32 ------
1> example.cpp
1>c:\projects\example\example\example.cpp(18): error C2027: use of undefined type 'boost::mpl::at<m,int>'
1>c:\projects\example\example\example.cpp(18): error C2065: 'type' : undeclared identifier
1>c:\projects\example\example\example.cpp(18): error C2146: syntax error : missing ';' before identifier 'a'
1>c:\projects\example\example\example.cpp(18): error C2065: 'a' : undeclared identifier
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I've installed VS Community 2013 Update 4. Am I using this incorrectly or is this a failure with the version I've installed? Release notes for 1.57.0 doesn't reference anything, nor does their bug system.
Basically there's a whole slew of missing headers. The last, simplest, one just misses
#include <boost/mpl/at.hpp>
#include <type_traits>
(that's on GCC, so MSVC might require some more due to implementation defined indirect header includes).
The full map sample needs at least
#include <boost/mpl/assert.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/size.hpp>
#include <type_traits>
And some more usings:
using boost::mpl::empty;
using boost::mpl::size;
Related
I'm using a pre-build 1.66 (lib32-msvc-14.0) that I've downloaded. I'm using Visual studio 2015.
I could run a sample without problem.
But in my project as soon as I include it( a simle wrapper), it generates a lot of errors.
here's my simple wrapper:
Net.h :
#ifndef _PCNET_h
#define _PCNET_h
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <boost/asio.hpp>
#include <string>
using boost::asio::ip::tcp;
typedef unsigned char byte;
typedef void(*newDataCallbackPtr)(byte cmd, byte *data, int len);
namespace net {
void init(std::string host, std::string port);
void send(byte cmd, byte *data, int len);
void registerCB(newDataCallbackPtr cb);
void join();
}
#endif
Net.cpp :
#include "Net.h"
const int max_length = 66000;
tcp::socket *s;
std::string delim = ";z|";
std::string recvData;
std::thread *t, *t2;
newDataCallbackPtr CB;
void readThrd();
//Public
void net::init(std::string host, std::string port) {
boost::asio::io_context io_context;
s = new tcp::socket(io_context);
tcp::resolver resolver(io_context);
boost::asio::connect(*s, resolver.resolve(host, port));
t = new std::thread([&io_context]() { io_context.run(); });
t2 = new std::thread(readThrd);
}
void net::send(byte cmd, byte *data, int len) {
byte *buff = new byte[len + 4];
buff[0] = cmd;
memcpy(buff + 1, data, len);
buff[len + 1] = ';';
buff[len + 2] = 'z';
buff[len + 3] = '|';
boost::asio::write(*s, boost::asio::buffer(buff, len + 4));
delete[] buff;
}
void net::registerCB(newDataCallbackPtr cb) {
CB = cb;
}
void net::join() {
t->join();
}
//Prv8
void readThrd() {
while (true)
{
size_t n = boost::asio::read_until(*s, boost::asio::dynamic_buffer(recvData), delim);
byte *buff = new byte[n - 3];
memcpy(buff, recvData.c_str(), n - 3);
recvData.erase(0, n);
CB(buff[0], buff + 1, (int)n - 4);
}
}
the rest of my project compiles without any problem. but as soon as i Include this Net.h (in another .cpp), compilers gives me a lot of errors in winuser and asio headers:
1>------ Build started: Project: pcMode, Configuration: Debug Win32 ------
1> PCutil.cpp
1> Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
1> - add -D_WIN32_WINNT=0x0501 to the compiler command line; or
1> - add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
1> Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
1>c:\program files (x86)\windows kits\8.1\include\um\winuser.h(5836): warning C4091: 'typedef ': ignored on left of 'tagINPUT' when no variable is declared
1>c:\program files (x86)\windows kits\8.1\include\um\winuser.h(5836): error C2143: syntax error: missing ';' before 'constant'
1>c:\program files (x86)\windows kits\8.1\include\um\winuser.h(5836): error C2059: syntax error: 'constant'
1>c:\program files (x86)\windows kits\8.1\include\um\winuser.h(5843): error C2061: syntax error: identifier 'LPINPUT'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(74): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(74): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(75): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(76): error C2976: 'boost::asio::detail::executor_binder_result_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(44): note: see declaration of 'boost::asio::detail::executor_binder_result_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(76): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(76): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(82): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(82): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(83): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(84): error C2976: 'boost::asio::detail::executor_binder_result_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(44): note: see declaration of 'boost::asio::detail::executor_binder_result_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(84): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(84): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(90): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(90): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(91): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(92): error C2974: 'boost::asio::detail::executor_binder_result_type': invalid template argument for 'T', type expected
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(44): note: see declaration of 'boost::asio::detail::executor_binder_result_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(92): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(92): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(98): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(98): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(99): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(100): error C2974: 'boost::asio::detail::executor_binder_result_type': invalid template argument for 'T', type expected
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(44): note: see declaration of 'boost::asio::detail::executor_binder_result_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(100): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(100): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): warning C4544: '<unnamed-symbol>': default template argument ignored on this template declaration
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(108): note: see declaration of '<unnamed-symbol>'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(118): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(118): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(119): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(120): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(120): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(120): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(124): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(124): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(125): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(126): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(126): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(126): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(134): warning C4544: '<unnamed-symbol>': default template argument ignored on this template declaration
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(133): note: see declaration of '<unnamed-symbol>'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(144): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(144): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(145): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(146): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(146): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(146): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(151): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(151): error C2059: syntax error: 'constant'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(152): error C2059: syntax error: ')'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(153): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(153): error C2143: syntax error: missing ';' before '{'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(153): error C2447: '{': missing function header (old-style formal list?)
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(219): error C2976: 'boost::asio::detail::executor_binder_argument_type': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(493): note: see reference to class template instantiation 'boost::asio::executor_binder<T,Executor>' being compiled
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(219): error C2955: 'boost::asio::detail::executor_binder_argument_type': use of class template requires template argument list
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(109): note: see declaration of 'boost::asio::detail::executor_binder_argument_type'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(220): error C2976: 'boost::asio::detail::executor_binder_argument_types': too few template arguments
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(134): note: see declaration of 'boost::asio::detail::executor_binder_argument_types'
1>c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(220): error C2955: 'boost::asio::detail::executor_binder_argument_types': use of class template requires template argument list
1> c:\boost\boost_1_66_0\boost\asio\bind_executor.hpp(134): note: see declaration of 'boost::asio::detail::executor_binder_argument_types'
1> Net.cpp
1> Please define _WIN32_WINNT or _WIN32_WINDOWS appropriately. For example:
1> - add -D_WIN32_WINNT=0x0501 to the compiler command line; or
1> - add _WIN32_WINNT=0x0501 to your project's Preprocessor Definitions.
1> Assuming _WIN32_WINNT=0x0501 (i.e. Windows XP target).
1> Generating Code...
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
as for PCutil. it has a lot of codes, I've removed irrelevant parts. here's the related parts:
PCutil.h:
#ifndef _PCUTIL_h
#define _PCUTIL_h
#include <iostream>
#include <chrono>
#include <thread>
#include <queue>
#include <stdarg.h>
#include "pinNameDef.h"
extern int ardDigitalPin2PinNum[];
#define HIGH 1
#define OUTPUT 1
#define LOW 0
#define INPUT 0
typedef unsigned char byte;
extern byte exE2PR[];
extern byte inE2PR[];
void PCSend(NETCMDS id, int len, byte b1 = 0, byte b2 = 0, byte b3 = 0, byte b4 = 0, byte b5 = 0, byte b6 = 0, byte b7 = 0, byte b8 = 0);
void PCSend(NETCMDS id, int len, byte *data);
void init(char* host, char* port);
void joinNet();
#endif
PCutil.cpp
#include "PCutil.h"
#include "pinNameDef.h"
#include "../spec.h"
#include "../config.h"
#include "Net.h"
byte exE2PR[PCE2PRSIZE];
byte inE2PR[PCE2PRSIZE];
void PCSend(NETCMDS id, int len, byte b1, byte b2, byte b3, byte b4, byte b5, byte b6, byte b7, byte b8) {
byte b[] = { b1,b2,b3,b4,b5,b6,b7,b8 };
net::send(id, b, len + 1);
}
void PCSend(NETCMDS id, int len, byte *data) {
net::send(id, data, len);
}
void netCB(byte cmd, byte *data, int len) {
//some codes
}
void init(char* host, char* port) {
Net init
net::registerCB(netCB);
net::init(host, port);
}
void joinNet() {
net::join();
}
any idea whats wrong here?
Thanks.
I am trying to build this program:
#include "stdafx.h"
#include <boost/interprocess/shared_memory_object.hpp>
#include <boost/interprocess/file_mapping.hpp>
#include <boost/interprocess/mapped_region.hpp>
using namespace std;
int main()
{
using boost::interprocess;
// Create the file mapping
file_mapping fm("input.dat", read_only);
// Map the file in memory
mapped_region region(fm, read_only);
// Get the address where the file has been mapped
float * addr = (float *)region.get_address();
std::size_t elements = region.get_size() / sizeof(float);
}
But I am having two problems, for the main I am getting:
1>tasker.cpp(98): error C2873: 'boost::interprocess' : symbol cannot be used in a using-declaration
1>tasker.cpp(101): error C2065: 'file_mapping' : undeclared identifier
1>tasker.cpp(101): error C2146: syntax error : missing ';' before identifier 'fm'
1>tasker.cpp(101): error C2065: 'read_only' : undeclared identifier
1>tasker.cpp(101): error C3861: 'fm': identifier not found
1>tasker.cpp(103): error C2065: 'mapped_region' : undeclared identifier
1>tasker.cpp(103): error C2146: syntax error : missing ';' before identifier 'region'
1>tasker.cpp(103): error C2065: 'fm' : undeclared identifier
1>tasker.cpp(103): error C2065: 'read_only' : undeclared identifier
1>tasker.cpp(103): error C3861: 'region': identifier not found
1>tasker.cpp(105): error C2065: 'region' : undeclared identifier
1>tasker.cpp(105): error C2228: left of '.get_address' must have class/struct/union
1> type is 'unknown-type'
1>tasker.cpp(106): error C2065: 'region' : undeclared identifier
1>tasker.cpp(106): error C2228: left of '.get_size' must have class/struct/union
1> type is 'unknown-type'
and for the #include <boost/interprocess/mapped_region.hpp> I am getting
1>C:\Users\Mike\Documents\boost_1_55_0\boost/intrusive/detail/has_member_function_callable_with.hpp(200): error C2228: left of '.select_on_container_copy_construction' must have class/struct/union
1> type is 'boost::move_detail::add_rvalue_reference<U>::type'
1> C:\Users\Mike\Documents\boost_1_55_0\boost/intrusive/detail/has_member_function_callable_with.hpp(276) : see reference to class template instantiation 'boost::container::container_detail::has_member_function_callable_with_select_on_container_copy_construction_impl<Fun,true,>' being compiled
1> with
1> [
1> Fun=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/container/allocator_traits.hpp(262) : see reference to class template instantiation 'boost::container::container_detail::has_member_function_callable_with_select_on_container_copy_construction<const Alloc,>' being compiled
1> with
1> [
1> Alloc=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/container/detail/tree.hpp(217) : see reference to class template instantiation 'boost::container::allocator_traits<A>' being compiled
1> with
1> [
1> A=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/container/detail/tree.hpp(246) : see reference to class template instantiation 'boost::container::container_detail::intrusive_rbtree_type<A,boost::container::container_detail::tree_value_compare<Key,std::pair<const Key,T>,Compare,boost::container::container_detail::select1st<std::pair<const Key,T>>>>' being compiled
1> with
1> [
1> A=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> , Key=const boost::interprocess::ipcdetail::sync_id *
1> , T=boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>
1> , Compare=boost::interprocess::ipcdetail::sync_handles::address_less
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/container/map.hpp(83) : see reference to class template instantiation 'boost::container::container_detail::rbtree<Key,std::pair<const Key,T>,boost::container::container_detail::select1st<std::pair<const Key,T>>,Compare,Allocator>' being compiled
1> with
1> [
1> Key=const boost::interprocess::ipcdetail::sync_id *
1> , T=boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>
1> , Compare=boost::interprocess::ipcdetail::sync_handles::address_less
1> , Allocator=std::allocator<std::pair<const boost::interprocess::ipcdetail::sync_id *const ,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<std::pair<const boost::interprocess::ipcdetail::sync_id,void *>>>>>
1> ]
1> C:\Users\Mike\Documents\boost_1_55_0\boost/interprocess/sync/windows/sync_utils.hpp(226) : see reference to class template instantiation 'boost::container::map<const boost::interprocess::ipcdetail::sync_id *,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<T>>,boost::interprocess::ipcdetail::sync_handles::address_less,std::allocator<std::pair<const Key,boost::unordered::iterator_detail::iterator<boost::unordered::detail::ptr_node<T>>>>>' being compiled
1> with
1> [
1> T=std::pair<const boost::interprocess::ipcdetail::sync_id,void *>
1> , Key=const boost::interprocess::ipcdetail::sync_id *
1> ]
I am using Visual Studio Express 2013 for Windows Desktop, and boost 1.55.0.
I tried other boost libraries and work without any issue.... Also, I am using the x64 release build.
Boost 1.55 does not fully supports Visual Studio 2013 compiler yet.
Either:
use Visual Studio 2012 toolchain
or try to get latest source from svn co http://svn.boost.org/svn/boost/trunk boost-trunk
or patch boost yourself (don't forget to upload your patch)
or wait until someone will patch it. You can speed it up by submitting bug report
Edit
Just checked boost-trunk, with boost/intrusive/detail/has_member_function_callable_with.hpp already patched and it compiles fine with both vs2013 and vs2013-nov-2013-ctp toolchains. So, try it. And, if you have multiple boost versions, don't forget to change include paths (in Makefile or VC project properties) as I did. ;)
Note, that, obviously, latest development code can be unstable. Do not use it for end-user production.
Try changing this:
using boost::interprocess;
to this:
using namespace boost::interprocess;
(Ref: Example in http://www.boost.org/doc/libs/1_55_0/doc/html/interprocess/quick_guide.html )
Yeah. you need to say "using namespace boost::interprocess;"
Fix that and you should be good.
I am attempting to print containers, like sets and maps. The book I am using says the following code is valid:
#include <iostream>
#include <set>
#include <iterator>
#include <fstream>
using namespace std;
template <typename Container>
void print (const Container & c, ostream & out = cout)
{
typename Container::const_iterator itr;
for( itr=c.begin(); itr!=c.end(); ++itr)
out << *itr << " ";
out << endl;
}
int main()
{
ifstream fin("Test.txt");
set<string> s( istream_iterator<string>(fin),
istream_iterator<string>() );
print( s );
return 0;
}
Yet I am getting the an error from Visual Studio's compiler. What am I missing? I know it is likely something simple like an include yet I am unfamiliar with STL Containers and C++ iterators.
I already have #include <iterator>
Errors:
'Container': must be a class or namespace when followed by '::'
'itr' : undeclared identifier
'const_iterator' : is not a member of '`global namespace''
and a few more I am sure are a result of the first one.
Edit:
Per the textbook, the following code should be equivalent to that in my main. I could not get it to work but it may help:
ifstream fin("Test.txt");
string x;
set<string> s;
while( fin >> x)
s.insert(x);
Edit:
Visual Studio build output:
------ Build started: Project: project, Configuration: Debug Win32 ------
Build started 4/15/2012 1:19:25 PM.
InitializeBuildStatus:
Touching "Debug\project.unsuccessfulbuild".
ClCompile:
Project4.cpp
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(11): error C2825: 'Container': must be a class or namespace when followed by '::'
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(22) : see reference to function template instantiation 'void print<std::set<_Kty>
(std::istream_iterator<_Ty>,std::istream_iterator<_Ty> (__cdecl *)(void))>(Container (__cdecl &),std::ostream &)' being compiled
with
[
_Kty=std::string,
_Ty=std::string,
Container=std::set<std::string> (std::istream_iterator<std::string>,std::istream_iterator<std::string> (__cdecl *)(void))
]
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(11): error C2039: 'const_iterator' : is not a member of '`global namespace''
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(11): error C2146: syntax error : missing ';' before identifier 'itr'
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(11): error C2065: 'itr' : undeclared identifier
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(12): error C2065: 'itr' : undeclared identifier
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(12): error C2228: left of '.begin' must have class/struct/union
type is 'std::set<_Kty> (__cdecl &)'
with
[
_Kty=std::string
]
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(12): error C2065: 'itr' : undeclared identifier
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(12): error C2228: left of '.end' must have class/struct/union
type is 'std::set<_Kty> (__cdecl &)'
with
[
_Kty=std::string
]
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(12): error C2065: 'itr' : undeclared identifier
c:\users\admin\documents\visual studio 2010\projects\project\project\project4.cpp(13): error C2065: 'itr' : undeclared identifier
Build FAILED.
Time Elapsed 00:00:01.00
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
It thinks this is a function declaration:
set<string> s( istream_iterator<string>(fin),
istream_iterator<string>() );
Adding an extra pair of parentheses will correct it:
set<string> s( (istream_iterator<string>(fin)),
istream_iterator<string>() );
There are many examples of this on SO if you search for Most Vexing Parse.
Edit: You also need to add #include <string>
Seems like the compilers (also clang++) seem to get confused. The following works for me, though:
#include <iostream>
#include <set>
#include <iterator>
#include <fstream>
using namespace std;
template <typename Container>
void print (const Container & c, ostream & out = cout)
{
typename Container::const_iterator itr;
for( itr=c.begin(); itr!=c.end(); ++itr)
out << *itr << " ";
out << endl;
}
int main()
{
ifstream fin("Test.txt");
istream_iterator<string> first(fin), last;
set<string> s(first, last);
print(s);
return 0;
}
However, I would recommend turning your print function into something which accepts an iterator range which which you output using std::copy, as is shown here: http://www.sgi.com/tech/stl/ostream_iterator.html
I have some troubles with the following code
#include<iostream>
#include<iomanip>
#include<fstream>
#include<vector>
#include<stack>
#include<queue>
#include<cstring>
#include<functional>
#include<algorithm>
using namespace std;
struct node
{
int weight;
unsigned char value;
const node * child0;
const node *child1;
node(unsigned char c=0,int i=-1){
value=c;
weight=-1;
child0=0;
child1=0;
}
//construct new internal node that has children c1 and c2
node (const node* c0,const node *c1){
value=0;
weight=c0->weight+c1->weight;
child0=c0;
child1=c1;
}
bool operator<(const node &a) const {
return weight<a.weight;
}
void traverse(char * code=" " ) const;
};
void node::traverse(char * code ) const
{
if(child0)
{
child0->traverse(code +'0');
child1->traverse(code +'1');
}
else
{
cout<<" "<<value <<" ";
cout<<setw(2)<<weight;
cout<<" "<<code<<endl;
}
}
void count_chars(int *counts)
{
for (int i=0;i<256;i++)
counts[i]=0;
//ifstream file( "input.data");
//if(!file){
//cerr<<" couldnt open input file!\n";
//throw "abort";
//file.setf(ios::skipws);
unsigned char c;
while(true)
{
cin>>c;
if(c){
counts[c]++;
}
else
break;
}
}
int main()
{
int counts[256];
count_chars(counts);
priority_queue<vector<node>,greater<node> >q;
for(int i=0;i<256;++i)
if(counts[i])
q.push(node(i,counts[i]));
while(q.size()<1)
{
node *child0=new node(q.top());
q.pop();
node *child1=new node(q.top());
q.pop();
q.push(node(child0,child1));
}
cout<<" char Symbol code "<<endl;
q.top().traverse();
return 0;
}
But it shows me some errors. For example unknown size of priority_queue and so on. Here is also the error list
1>------ Build started: Project: HUffman_coding, Configuration: Debug Win32 ------
1> HUffman_coding.cpp
1>c:\program files\microsoft visual studio 10.0\vc\include\queue(212): error C2039: 'value_type' : is not a member of 'std::greater<_Ty>'
1> with
1> [
1> _Ty=node
1> ]
1>c:\program files\microsoft visual studio 10.0\vc\include\queue(212): error C2146: syntax error : missing ',' before identifier 'value_type'
1>c:\program files\microsoft visual studio 10.0\vc\include\queue(212): error C2065: 'value_type' : undeclared identifier
1>c:\users\daviti\documents\visual studio 2010\projects\huffman_coding\huffman_coding\huffman_coding.cpp(100): error C3203: 'less' : unspecialized class template can't be used as a template argument for template parameter '_Pr', expected a real type
1>c:\users\daviti\documents\visual studio 2010\projects\huffman_coding\huffman_coding\huffman_coding.cpp(100): error C2955: 'std::less' : use of class template requires template argument list
1> c:\program files\microsoft visual studio 10.0\vc\include\xfunctional(121) : see declaration of 'std::less'
1>c:\users\daviti\documents\visual studio 2010\projects\huffman_coding\huffman_coding\huffman_coding.cpp(100): error C2133: 'q' : unknown size
1>c:\users\daviti\documents\visual studio 2010\projects\huffman_coding\huffman_coding\huffman_coding.cpp(100): error C2512: 'std::priority_queue' : no appropriate default constructor available
1>c:\users\daviti\documents\visual studio 2010\projects\huffman_coding\huffman_coding\huffman_coding.cpp(103): error C2663: 'std::priority_queue<_Ty,_Container,_Pr>::push' : 2 overloads have no legal conversion for 'this' pointer
1>c:\users\daviti\documents\visual studio 2010\projects\huffman_coding\huffman_coding\huffman_coding.cpp(104): error C2662: 'std::priority_queue<_Ty,_Container,_Pr>::size' : cannot convert 'this' pointer from 'std::priority_queue' to 'const std::priority_queue<_Ty,_Container,_Pr> &'
1> Reason: cannot convert from 'std::priority_queue' to 'const std::priority_queue<_Ty,_Container,_Pr>'
1> Conversion requires a second user-defined-conversion operator or constructor
1>c:\users\daviti\documents\visual studio 2010\projects\huffman_coding\huffman_coding\huffman_coding.cpp(104): fatal error C1903: unable to recover from previous error(s); stopping compilation
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
I have also recognized that, when I am trying to do like this q.top().traverse() after top. it does not show me traverse option. What is wrong?
I think that instead of
priority_queue<vector<node>,greater<node> >q;
you meant to write:
priority_queue<node, vector<node>, greater<node> >q;
That should solve the errors you're seeing at the moment.
And like I suggested, please do properly format your code. It will make everything so much easier to read and probably makes receiving answers more likely.
I'm trying to create a threadpool with the boost threadpool library, but on defining it I keep getting lots of error about template params being wrong.
I'm probably doing something fundamentally wrong, but I'm not seeing it?
//Threadpool
typedef boost::threadpool::thread_pool<
boost::threadpool::task_func,
boost::threadpool::fifo_scheduler<tsk>,
boost::threadpool::static_size<boost::threadpool::fifo_pool>,
boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
> pool;
ERRORS:
------ Build started: Project: Trial, Configuration: Debug Win32 ------
Compiling...
Trial.cpp
error C2923: 'boost::threadpool::fifo_scheduler' : 'tsk' is invalid as template argument '#1', type expected
see declaration of 'tsk'
error C3200: 'boost::threadpool::fifo_pool' : invalid template argument for template parameter 'SizePolicy', expected a class template
error C3200: 'boost::threadpool::resize_controller<Pool>' : invalid template argument for template parameter 'SizePolicyController', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
error C3200: 'boost::threadpool::wait_for_active_tasks<Pool>' : invalid template argument for template parameter 'ShutdownPolicy', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
error C3200: 'boost::threadpool::fifo_pool' : invalid template argument for template parameter 'SizePolicy', expected a class template
see reference to class template instantiation 'boost::threadpool::thread_pool<Task,SchedulingPolicy,SizePolicy,SizePolicyController,ShutdownPolicy>' being compiled
with
[
Task=boost::threadpool::task_func,
SchedulingPolicy=boost::threadpool::fifo_scheduler,
SizePolicy=boost::threadpool::fifo_pool,
SizePolicyController=boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
ShutdownPolicy=boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(79) : error C3200: 'boost::threadpool::resize_controller<Pool>' : invalid template argument for template parameter 'SizePolicyController', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(79) : error C3200: 'boost::threadpool::wait_for_active_tasks<Pool>' : invalid template argument for template parameter 'ShutdownPolicy', expected a class template
with
[
Pool=boost::threadpool::fifo_pool
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(91) : error C2059: syntax error : '<'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(91) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(92) : error C2059: syntax error : '<'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(92) : error C2238: unexpected token(s) preceding ';'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(111) : error C2146: syntax error : missing ';' before identifier 'size_controller'
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(111) : error C2501: 'boost::threadpool::thread_pool<Task,SchedulingPolicy,SizePolicy,SizePolicyController,ShutdownPolicy>::size_controller_type' : missing storage-class or type specifiers
with
[
Task=boost::threadpool::task_func,
SchedulingPolicy=boost::threadpool::fifo_scheduler,
SizePolicy=boost::threadpool::fifo_pool,
SizePolicyController=boost::threadpool::resize_controller<boost::threadpool::fifo_pool>,
ShutdownPolicy=boost::threadpool::wait_for_active_tasks<boost::threadpool::fifo_pool>
]
c:\Program Files\boost\boost_1_44\boost\threadpool\pool.hpp(112) : warning C4183: 'size_controller': missing return type; assumed to be a member function returning 'int'
---------------------- Done ----------------------
Build: 0 succeeded, 1 failed, 0 skipped
According to your comment, tsk is a variable. You can't pass runtime expressions (such as a variable) as template parameters. Templates are entirely compile-time.
For this specific problem, you just need to do this:
typedef boost::threadpool::thread_pool<> pool;
void taskfunc();
// later on...
pool my_pool;
my_pool.schedule(&taskfunc);
boost::threadpool::task_func is just a boost::function0<void> — any 0-arg void function pointer can convert to that type.