Originally Posted by
iMalc
Come on cpjust, you've been here long enough to stop making the stupid newbie mistake of not posting the compile errors!
OK, but you asked for it.
Code:
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(1372) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(142) : while compiling class template member function 'bool std::less<_Ty>::operator ()(const _Ty &,const _Ty &) const'
with
[
_Ty=std::string
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\map(72) : see reference to class template instantiation 'std::less<_Ty>' being compiled
with
[
_Ty=std::string
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(26) : see reference to class template instantiation 'std::_Tmap_traits<_Kty,_Ty,_Pr,_Alloc,_Mfl>' being compiled
with
[
_Kty=std::string,
_Ty=std::vector<double>,
_Pr=std::less<std::string>,
_Alloc=std::allocator<std::pair<const std::string,std::vector<double>>>,
_Mfl=false
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(68) : see reference to class template instantiation 'std::_Tree_nod<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,std::vector<double>,std::less<std::string>,std::allocator<std::pair<const std::string,std::vector<double>>>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(94) : see reference to class template instantiation 'std::_Tree_ptr<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,std::vector<double>,std::less<std::string>,std::allocator<std::pair<const std::string,std::vector<double>>>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(112) : see reference to class template instantiation 'std::_Tree_val<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,std::vector<double>,std::less<std::string>,std::allocator<std::pair<const std::string,std::vector<double>>>,false>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\map(82) : see reference to class template instantiation 'std::_Tree<_Traits>' being compiled
with
[
_Traits=std::_Tmap_traits<std::string,std::vector<double>,std::less<std::string>,std::allocator<std::pair<const std::string,std::vector<double>>>,false>
]
..\src\main.cpp(176) : see reference to class template instantiation 'std::map<_Kty,_Ty>' being compiled
with
[
_Kty=std::string,
_Ty=std::vector<double>
]
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(1372) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(1372) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::_Tree<_Traits> &,const std::_Tree<_Traits> &)' : could not deduce template argument for 'const std::_Tree<_Traits> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\xtree(1372) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\vector(1276) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\vector(1276) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\vector(1276) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::vector<_Ty,_Alloc> &,const std::vector<_Ty,_Alloc> &)' : could not deduce template argument for 'const std::vector<_Ty,_Alloc> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\vector(1276) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\xutility(1880) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\xutility(1880) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\xutility(1880) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::reverse_iterator<_RanIt> &,const std::reverse_iterator<_RanIt2> &)' : could not deduce template argument for 'const std::reverse_iterator<_RanIt> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\xutility(1880) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\utility(76) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\utility(76) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\utility(76) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2784: 'bool std::operator <(const std::pair<_Ty1,_Ty2> &,const std::pair<_Ty1,_Ty2> &)' : could not deduce template argument for 'const std::pair<_Ty1,_Ty2> &' from 'const std::string'
c:\Program Files\Microsoft Visual Studio 8\VC\include\utility(76) : see declaration of 'std::operator <'
c:\Program Files\Microsoft Visual Studio 8\VC\include\functional(143) : error C2676: binary '<' : 'const std::string' does not define this operator or a conversion to a type acceptable to the predefined operator
Here's everything including the "..."
Code:
#include <windows.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stdexcept>
#include <climits>
#include <ctime>
#include <conio.h>
using namespace std;
vector<unsigned char>
GetData( size_t size )
{
vector<unsigned char> data;
for ( size_t i = 0; i < size; ++i )
{
data.push_back( static_cast<unsigned char>( i % UCHAR_MAX ) );
}
random_shuffle( data.begin(), data.end() );
return data;
}
double
TimedWrite( const char* filename,
size_t megaBytes )
{
// In case the file exists, delete it.
DeleteFile( filename );
DWORD dwFlags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH;
// Create a new file.
HANDLE file = CreateFile( filename,
GENERIC_WRITE, // dwDesiredAccess
0, // dwShareMode
NULL, // lpSecAttr
CREATE_NEW, // dwCreateDisp
dwFlags,
NULL ); // hTemplateFile
if ( file == INVALID_HANDLE_VALUE )
{
cerr << "Error opening file: " << filename << endl;
throw runtime_error( "Error opening file!" );
}
const size_t bufSize = 1024 * 1024;
vector<unsigned char> megabyte( GetData( bufSize ) );
unsigned long bytesWritten = 0;
// Start timing.
SYSTEMTIME start;
GetSystemTime( &start );
for ( size_t i = 0; i < megaBytes; ++i )
{
if ( WriteFile( file,
&megabyte[0],
bufSize,
&bytesWritten,
NULL ) == FALSE )
{
cerr << "Error writing to file!" << endl;
throw runtime_error( "Error writing to file!" );
}
}
SYSTEMTIME end;
GetSystemTime( &end );
if ( CloseHandle( file ) == FALSE )
{
cerr << "Error closing file!" << endl;
throw runtime_error( "Error closing file!" );
}
// Compare end - start times.
size_t msDiff = ((end.wMinute * 60 * 1000) - (start.wMinute * 60 * 1000)) +
((end.wSecond * 1000) - (start.wSecond * 1000)) +
(end.wMilliseconds - start.wMilliseconds);
double dMB = megaBytes;
double dTime = msDiff;
double MBperSec = dMB / (dTime / 1000.0);
return MBperSec;
}
double
TimedRead( const char* filename,
size_t megaBytes )
{
DWORD dwFlags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_WRITE_THROUGH;
// Open an existing file.
HANDLE file = CreateFile( filename,
GENERIC_READ, // dwDesiredAccess
0, // dwShareMode
NULL, // lpSecAttr
OPEN_EXISTING, // dwCreateDisp
dwFlags,
NULL ); // hTemplateFile
if ( file == INVALID_HANDLE_VALUE )
{
cerr << "Error opening file: " << filename << endl;
throw runtime_error( "Error opening file!" );
}
const size_t bufSize = 1024 * 1024;
vector<unsigned char> megabyte( bufSize );
unsigned long bytesRead = 0;
// Start timing.
SYSTEMTIME start;
GetSystemTime( &start );
for ( size_t i = 0; i < megaBytes; ++i )
{
if ( (ReadFile( file,
&megabyte[0],
bufSize,
&bytesRead,
NULL ) == FALSE) || (bytesRead != bufSize) )
{
cerr << "Error reading from file!" << endl;
throw runtime_error( "Error reading from file!" );
}
}
SYSTEMTIME end;
GetSystemTime( &end );
if ( CloseHandle( file ) == FALSE )
{
cerr << "Error closing file!" << endl;
throw runtime_error( "Error closing file!" );
}
// Compare end - start times.
size_t msDiff = ((end.wMinute * 60 * 1000) - (start.wMinute * 60 * 1000)) +
((end.wSecond * 1000) - (start.wSecond * 1000)) +
(end.wMilliseconds - start.wMilliseconds);
double dMB = megaBytes;
double dTime = msDiff;
double MBperSec = dMB / (dTime / 1000.0);
return MBperSec;
}
void
TimedReadWrite( vector<pair<string, size_t> >& filenames,
double& avgRead,
double& avgWrite,
double& minRead,
double& maxRead,
double& minWrite,
double& maxWrite )
{
typedef vector<pair<string, size_t> >::iterator fileIter;
double speed = 0.0;
map<string, vector<double> > readSpeedsPerFile;
map<string, vector<double> > writeSpeedsPerFile;
avgRead = 0;
avgWrite = 0;
for ( int i = 0; i < 10; ++i )
{
for ( fileIter it = filenames.begin(); it != filenames.end(); ++it )
{
string filename( it->first );
size_t fileSize = it->second;
speed = TimedWrite( filename.c_str(), fileSize );
avgWrite += speed;
// writeSpeedsPerFile[filename].push_back( speed );
speed = TimedRead( filename.c_str(), fileSize );
avgRead += speed;
// readSpeedsPerFile[filename].push_back( speed );
DeleteFile( filename.c_str() );
}
}
vector<double> minReadPerFile;
vector<double> maxReadPerFile;
vector<double> minWritePerFile;
vector<double> maxWritePerFile;
typedef map<string, vector<double> >::iterator iter;
for ( iter it = readSpeedsPerFile.begin(); it != readSpeedsPerFile.end(); ++it )
{
minReadPerFile.push_back( *min_element( it->second.begin(), it->second.end() ) );
maxReadPerFile.push_back( *max_element( it->second.begin(), it->second.end() ) );
}
for ( iter it = writeSpeedsPerFile.begin(); it != writeSpeedsPerFile.end(); ++it )
{
minWritePerFile.push_back( *min_element( it->second.begin(), it->second.end() ) );
maxWritePerFile.push_back( *max_element( it->second.begin(), it->second.end() ) );
}
minRead = *min_element( minReadPerFile.begin(), minReadPerFile.end() );
maxRead = *max_element( maxReadPerFile.begin(), maxReadPerFile.end() );
minWrite = *min_element( minWritePerFile.begin(), minWritePerFile.end() );
maxWrite = *max_element( maxWritePerFile.begin(), maxWritePerFile.end() );
avgWrite /= 10;
avgRead /= 10;
}
int main()
{
typedef pair<string, size_t> FileAndSize;
vector<FileAndSize> filenames;
filenames.push_back( FileAndSize( "1MB.fil", 1 ) );
filenames.push_back( FileAndSize( "10MB.fil", 10 ) );
filenames.push_back( FileAndSize( "50MB.fil", 50 ) );
filenames.push_back( FileAndSize( "100MB.fil", 100 ) );
double avgRead = 0.0;
double avgWrite = 0.0;
double minRead = 0.0;
double maxRead = 0.0;
double minWrite = 0.0;
double maxWrite = 0.0;
TimedReadWrite( filenames,
avgRead,
avgWrite,
minRead,
maxRead,
minWrite,
maxWrite );
cout << "Read speed:" << endl
<< " Average:" << avgRead << "MB/s." << endl
<< " Minimum:" << minRead << "MB/s." << endl
<< " Maximum:" << maxRead << "MB/s." << endl
<< "Write speed:" << endl
<< " Average:" << avgWrite << "MB/s." << endl
<< " Minimum:" << minWrite << "MB/s." << endl
<< " Maximum:" << maxWrite << "MB/s." << endl;
cout << endl << "Press any key to continue." << endl;
_getch();
return 0;
}
I didn't think the rest would be relevent to the errors since it compiles just fine with those lines commented out, but as soon as I uncomment one of them, I get that huge mess of STL error hell.
So I assumed I must have been doing something wrong by using map:: operator[] in that way.