boost split compile issue - c++

I have the following code snippet. I am compiling using the sun studio 12 compiler and have tried boost 1.33 and 1.39
#include <boost/algorithm/string.hpp>
#include <string>
#include <vector>
using namespace boost;
using namespace std;
int main(int argc, char* argv[])
{
string exbyte = "0x2430";
string exbytes = "0x2430,2430";
typedef vector< string > SplitVec;
SplitVec res1 ;
split(res1 , exbyte, is_any_of(",") );
return 0
}
I get the following compile error:
"/bb/source/boost/boost_1_39_0/boost/algorithm/string/iter_find.hpp", line 175: Error, nomatchoverin: Could not find a match for std::vector::vector(boost::transform_iterator, boost::algorithm::split_iterator, boost::use_default, boost::use_default>, boost::transform_iterator, boost::algorithm::split_iterator, boost::use_default, boost::use_default>) needed in boost::algorithm::iter_split, std::string, boost::algorithm::detail::token_finderF>>(std::vector&, std::string &, boost::algorithm::detail::token_finderF>)
If anybody has thoughts on this that would be awesome. Since I am cotemplateing strtok(only kidding)

Other than the missing semi-colon after return 0, which I assume is an unrelated typo, your code compiles fine for me, using gcc 4.3.2.
According to the documentation for boost::split, you're using the function correctly, so I don't think this is a coding error. Are you sure you have boost installed correctly?
Edit: It may be that Boost doesn't support your particular compiler, so parts of boost may not work for you. See here for a list of supported compilers, along with various issues which affect each compiler.

It sounds like your compiler's STL implementation only provides a vector ctor taking vector::iterator's and not any iterator class. You can verify this by taking a look at the vector header file.
You may able to work around this by using STLPort which apparently can be used with Sun Studio 12.

Related

(Software issue) Can anyone suggest a download that will definitely bring my Mingw32 compiler up to speed?

#include <iostream>
#include <string>
using namespace std;
int main(){
string s = "wassup", newVal = "though";
cout << *(s.insert(s.begin(), newVal.begin(), newVal.end()));
}
This brings up the problem that the return type of string's insert member function is void (error: void value not ignored as it ought to be). This link indicates C++98 returns void but the "new" standard C++11 does indeed return an iterator.
A bit of context, I actually faced this problem earlier. I was/am using CodeBlocks (GCC Compiler Collection) on Windows 7 64-bit and this program gave the same issue (dereferencing void):
#include <iostream>
#include <list>
int main(){
list<int> x = {1,2,3,4};
*(x.insert(++x.begin(), 3, 2));
for(auto c : x)
cout << c;
}
I posted my issue on a different forum and a user pointed out Mingw32 was missing that particular C++11 change, indicating Mingw-w64 does not have this issue. So I went straight to installing Mingw-w64 on Code::Blocks using this guide and the problem was resolved. It's only now I've found out that the overloaded function which takes three iterator parameters STILL returns void.
I'm a little confused as to why Code::Blocks Mingw32 didn't supply a fully updated C++11 standard. Can anyone suggest a download that will definitely bring my compiler up to speed?

C++ std::array don't work on my local compiler

I follow this example array::size, but it's don't work on my Dev C++ IDE, and I don't know why.
I tried to run on Code Blocks but it's still the same.
I think code is correct but how to fix this problem
here is my code
#include <iostream>
#include <array>
using namespace std;
void useArray()
{
array<int,4> myInts;
myInts[0]=1;
cout<<"Size of Array: "<<myInts.size();
}
int main()
{
useArray();
system("pause");
}
And this is compiler error:
std::array is C++11 only. Dev-C++ does not support C++11.
If you're just looking for options to Visual Studio this article is the right starting place: http://www.cplusplus.com/articles/36vU7k9E/
In the case that you're using a compiler that does not support C++11 (using the flag: -std=c++11) you always have the chance to use a Boost alternative.
Boost comes with the Boost Array Library which is an STL conform Array. The generated code will be similar to a C Array while having the opportinity to use additionnal methods on it e.g determinate the array size. All this basically works as the C++11 version of an Array.
It lives in the 'boost' namespace instead of 'std' therefore you need to include the following header to use it:
#include <boost/array.hpp>
You should then set a typedef declaration for the Boost Array:
typedef boost::array<std::string, 3> array;
// The 3 stands for the number of elements the array can hold
Implementing one of these Arrays is then fairly simple:
array a;

Yet Another: Passing Vector of Structs to Function - C++, MinGW

I am aware there are numerous similar queries on here, however I haven't been able to resolve this, not has a colleague, so:
I am using MinGW (4.8.x) with Eclipse CDT Kepler.
1) I have my own code and to clean it up I changed it to use a vector of structs - all is fine, except that the function that receives it complains about Invalid Argument'.
2) I reduced my code down to a minimum working example, if I place it all in a single file it works, however if I move out my definitions to the header (which I need to do in my main code) it suddenly cannot resolve the fields in the struct...
The code below is for a three file configuration, header/function/main.
(In my main code I use namespace std - but that doesn't seem to be the problem. Also, there are extraneous headers for a minimum working example in this, however they are needed in my main code.)
myheaders.h
/*************************/
/****** myheaders.h ******/
/*************************/
/**-- Header Files --**/
// File Streams and IO
#include <stdio.h>
#include <sstream>
#include <iostream>
#include <fstream>
// For strtod -> string to double
#include <stdlib.h>
// Math Operations
//#include <math.h>
#include <cmath>
// To get the CPU time
#include <time.h>
// For Vectors
#include <vector>
// For strings, C strings right now...
#include <cstring>
// Needed globally for the function definitions
// using namespace std;
#ifndef MY_HEADERS
#define MY_HEADERS
struct SpeciesLoss {
int ReactionID;
int SpeciesID;
double coefficient;
};
std::vector< double > SpeciesLossRate(std::vector<SpeciesLoss> , int, const std::vector< double > & );
#endif
function.cpp
/*************************/
/****** function.cpp *****/
/*************************/
#include "myheaders.h"
std::vector< double > SpeciesLossRate(
std::vector< SpeciesLoss > SpeciesLossList,
int Number_Species,
const std::vector< double >& Combined_Rates
)
{
std::vector< double > temp_species_loss;
temp_species_loss.resize(1);
temp_species_loss[0]=SpeciesLossList[0].ReactionID;
return temp_species_loss;
}
main.cpp
/*************************/
/******** main.cpp *******/
/*************************/
#include "myheaders.h"
std::vector< SpeciesLoss > SpeciesLossAll; // New vector for recording species loss, uses a vector of structs
int main(int argc, char* argv[])
{
std::vector< double > Rates;
Rates.push_back(1);
SpeciesLossAll.push_back(SpeciesLoss());
SpeciesLossAll[0].ReactionID = 0;
SpeciesLossAll[0].SpeciesID = 0;
SpeciesLossAll[0].coefficient = 0;
std::vector< double > SpeciesConcentrationChange = SpeciesLossRate(SpeciesLossAll,1, Rates);
return 0;
}
Edit:
Screenshot
Edit 2:
And interesting update - it compiles fine on Linux with GCC. Better than nothing, but I still want to know what is going wrong, plus I'd like my code to be cross platform...
Edit 3:
This is more and more bizarre - I just tested my code (the full project that compiles on Linux) on my home PC which runs Windows 7 where it builds fine while my laptop runs Windows 8 and the problem occurs.
The Settings for the C++ build are absolutely identical.
Both run MinGW 4.8.1...
Both run the latest Eclipse Kepler...
And yes, I am aware that I need to test some suggestions still.
#ifndef MY_HEADERS
#define MY_HEADERS
Should be at the beginning of your file. Since you have no idea in what order the compiler is going to include headers this might be causing a problem... Especially if you are including your personal header in multiple files, wich will definitely make it behave like so. Also, keep in mind that since you are not providing a default constructor but rather using the one the compiler provides for you, those variables inside the struct will most likely not be initialized to zero as you expect them.
EDIT#1
Are you compiling everything NOT just main... I just copied your code into VS and it works!
EDIT#2
Try defining the function inline instead of a separate implementation file.
static std::vector< double > SpeciesLossRate(
std::vector< SpeciesLoss > SpeciesLossList,
int Number_Species,
const std::vector< double >& Combined_Rates
)
{
std::vector< double > temp_species_loss;
temp_species_loss.resize(1);
temp_species_loss[0]=SpeciesLossList[0].ReactionID;
return temp_species_loss;
}
EDIT#3
Ok, from the screen-shot this is definitely valid code. For sake of trying everything; implement your own constructor and copy constructor of the struct. I know this might sound silly but maybe Eclipse doesn't think so.
OK - I have found the answer - I think - and it boils down to Eclipse.
-> Project -> C/C++ Index -> Rebuild
This resolves the issue.
In fact, this problem is known on earlier Eclipse CDT versions: https://bugs.eclipse.org/bugs/show_bug.cgi?id=348170

Using template functions in Visual Studio C++ 6.0

0Dear StackExchange Community,
I have for two hours tried to find the source of the problem but failed completly. Research=google search also did not provide any viable solutions. At least I was able to discover that under VS 6.0 one cannot split the declaration and implementation of a template function between header and .cpp-file.
Perhaps my approach is inherently flawed or it is VS 6.0 that is being particulary obnoxious this time.
Here is the test code I wrote.
#include "stdafx.h"
#include <string>
#include <iostream>
class TestClass{
public:
template<class T> inline bool isNull(T& inObject){
return 0; // edited because of the answer by Joachim Pileborg :)
// initial code was: return (inObject != NULL) ? 0:1;
}
};
using namespace std;
int main(int argc, char* argv[])
{
cout<<TestClass::isNull<string>("test");
return 0;
}
Running this code causes the following error:
fatal error C1001: INTERNER COMPILER- FEHLER
(Compiler-File "msc1.cpp", Row 1794)
Does anybody have an idea what I am doing wrong here?
P.S. : this time i really endevoured to ask the question as precisly as possible also providing a concrete example. Please let me know if there is anything else I should have added.
P.SS: I know that visual studio 6.0 ist pretty old but I am forced to use it at work. Running the same code with the a new compiler (at home) did not cause any errors. This is why I assume that the problem is mainly caused by the whims of VS 6.0.
Thanks in advance for you help !!
JD
Unless you define a custom casting operator that returns a pointer, an object instance can never be equal to NULL.
Apart from facts noted in comments and answers, internal compiler error happens in situation, when there's a bug in the compiler, that prevents it from compiling valid code.
Microsoft usually fixes these bugs in IDE hotfixes or in newer versions of compilers. Try to modify the structure of code such that it does the same thing, but looks differently - it's the only way to avoid the Internal Error problem.
There are several troubles in your code:
I rewrote it this way:
comparing the adress of the reference you're passing (you have edited your question but you wrote inObject==NULL in the body of your function and it couldn't compile either)
using const string& so has to be able to call TestClass::isNull<string>("test");
you must define your function as static if you want to call it the way you do
I'm not sure but the character '<' following your word template looked badly encoded in my IDE, so I replaced it with a commonplace <, it compiled better
it's a way of coding, but prefer using typename than class when defining templates
prefer using true and false instead of 1 and 0 ( you edited your question but you still return 0...)
=>
#include <string>
#include <iostream>
class TestClass{
public:
template<typename T>
static bool isNull(const T& inObject)
{
return (&inObject == NULL) ? true : false;
}
};
using namespace std;
int main(int argc, char* argv[])
{
cout<< TestClass::isNull<string>("test");
return 0;
}
Now it compiles fine.

Is std::ofstream movable?

I have this map which compiles fine in MSVC10 :
std::map<std::string, std::ofstream> m_logFiles;
But on ubuntu using g++ 4.5 with C++0x enabled, I get the following error message :
/usr/include/c++/4.5/bits/ios_base.h|785|error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private
By using pointers instead of objects, I resolved the problem.
Searching on the web, I learned that streams are not meant to be copied (the why was well explained). But my question is, is std::ofstream a movable type ? If it is, shouldn't it allow its use as a template parameter in the standard containers ?
If yes, then is g++ behind MSVC10 on this point ? (which would explain why it works on MSVC). I know it would be silly to ask compiler writers to fully implement something that isn't even final, but I'm curious regarding the future.
Using g++ 4.6.1 didn't help.
Edit : reading the comments I dug a little bit further and found that the insert is causing the problem, not the declaration of the map.
Reading Cubbi's link I tried the following :
#include <string>
#include <fstream>
#include <map>
using namespace std;
int main()
{
map<string, ofstream> m_logFiles;
ofstream st;
m_logFiles.insert(make_pair<string, ofstream>(string("a"), move(st)));
return 0;
}
But still no luck. g++ complains about the use of b deleted copy constructor.
std::ofstream is movable. This program compiles for me using clang/libc++:
#include <string>
#include <fstream>
#include <map>
int main()
{
std::map<std::string, std::ofstream> m_logFiles;
}
Reference 27.9.1.11 [ofstream.cons].
I asked a similar question earlier, and later found that GCC doesn't seem to support movable fstreams yet (I just tested GCC 4.6.1) as detailed in this answer.