i have one text file that contains only one line the line only contains one math expression
for example 12+(3.0*(4)-1)/sqrt(121)
my program needs to read this express as string and then give the result
13
is there any simple way or 3rd party dll/lib to make this out?
COMMENT ADDED:
http://stackoverflow.com/questions/928563/code-golf...
Say I have
double xSquared( const double )
{
return x*x;
}
...
std::function<double (double)> func = &xSquared;
...
which works fine for the (more complicated) purposes I use this structure, up till now. Now I have a function that accepts a std::function of the above form and I need to create a new std::function that extends the ...
I have the following code (I'm sorry for the lengthiness):
double primeValue( const func1D &func,
const double lowerBound, const double upperBound,
const double pole )
{
// check bounds
if( lowerBound >= upperBound )
throw runtime_error( "lowerBound must be smaller than upperBound!" ...
I've seen two recent answers using _1 as a pure C++0x solution (no explicit mention of boost lambdas).
Is there such an animal as std::_1 I would think that having native lambdas will make such a construct redundant.
A Google code search for std::_1 brings two results from the same project so that's inconclusive.
...
I'm experimenting with C++0x support and there is a problem, that I guess shouldn't be there. Either I don't understand the subject or gcc has a bug.
I have the following code, initially x and y are equal. Thread 1 always increments x first and then increments y. Both are atomic integer values, so there is no problem with the increment ...
i am using visual c++ 2010 can i run this code?
what should i add to visual studio?
...
How do I get a reference to a "get"-function for a specific tuple instance?
My best try is given below but does not compile against g++4.5.1
#include <tuple>
#include <string>
typedef std::tuple<int,std::string> Tuple;
auto t=(std::string& (Tuple&))(std::get<1,Tuple>);
The compiler error is:
a.cc:5: error: invalid cast to function ...
I need a easy way to assert inside a template that a template parameter implements a method (or one of its parent classes). I've read Concept check library but is hard to find an easy example to do simple checks like this one.
I've tried to follow other posts (like this one and this other one), which i've modified so i can make it gener...
Given GMan's deliciously evil auto_cast utility function concocted here, I've been trying to figure out why it doesn't compile for me when I'm trying to auto_cast from an rvalue (on MSVC 10.0).
Here's the code that I'm using:
template <typename T>
class auto_cast_wrapper : boost::noncopyable
{
public:
template <typename R>
fr...
Hi,
Let's say that we want to make class A thread-safe using an std::mutex. I am having my copy constructor and assignment operator similarly to the code below:
#include <mutex>
class A {
private:
int i;
mutable std::mutex mtx;
public:
A() : i(), mtx() { }
A(const A& other) : i(), mtx()
{
std::lock_guard<std::mutex> _l...
I'd like to know how are tuple implemented in standard library for C++0x. I tried to read description in libstdc++ manual and then read template listing, but it's really hard to understand how it works, especially when reading code.
Can someone explain me in few sentences the idea of tuple implementation? I want to know this, because I ...
In other thread I introduced some techniques we would use for Model-Driven-Development in C++ once the C++0x, in particular user-defined literals, is available. I just revised the plans for GCC 4.5 and even 4.6 and it shows that this particular feature is not supported.
Anyway, do you know if I even have any compiler to test that featur...
Edit:
So this question was misinterpreted to such a ludicrous degree that it has no point anymore. I don't know how, since the question that I actually asked was whether my specific implementation of thisyes, known to be pointless, yes, not remotely resembling idiomatic C++macro was as good as it could be, and whether it necessarily had...
class C
{
public:
C() : arr({1,2,3}) //doesn't compile
{}
/*
C() : arr{1,2,3} //doesn't compile either
{}
*/
private:
int arr[3];
};*/
I believe the reason is that arrays can be initialized only with = syntax, that is:
int arr[3] = {1,3,4};
Questions
How can I do what I want to do (that
is, initialize an array in a
...
Am I doing something wrong (again)?
#include <iostream>
using std::cout;
struct Map
{
Map()
{
cout << "Map()\n";
}
Map(const Map& pattern)
{
cout << "Map(const Map& pattern)\n";
}
Map(Map&& tmp)
{
cout << "Map(Map&& tmp)\n";
}
};
Map createMap()
{
return Map();
}
int m...
template<typename T>
std::istream & read(std::istream & istr, typename std::enable_if<std::is_pod<T>::value, T>::type & value)
{
return istr.read( reinterpret_cast<char*>(&value), sizeof(T));
}
int main()
{
int x;
read(cin, x); // error here
}
error C2783: 'std::istream &read(std::istream &,std::enable_if<std::tr1::is_pod...
I've just rewritten the following C89 code, that returns from the current function:
// make sure the inode isn't open
{
size_t i;
for (i = 0; i < ARRAY_LEN(g_cpfs->htab); ++i)
{
struct Handle const *const handle = &g_cpfs->htab[i];
if (handle_valid(handle))
{
if (handle->ino == (*inode)->i...
Possible Duplicates:
C subset of C++ -> Where not ? examples ?
Should portable C compile as C++?
Is every C program also valid C++?
And is every C++ program also valid under c++0x?
I seem to remember that there is a difference between how c and c++ handle enums that is not compatible, but don't remember what (or if) it is, o...