473,387 Members | 1,517 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to make a "synthetic" lvalue?

Most probably what I am asking for already has been
answered somewhere, still I was not able to find:-(

I want to encapsulate a class ( a primitive type for
the beginning ) to behave like a lvalue, but instead
of living in process memory being forwarded to some
remote store.

I believe an lvalue needs to be able to be convertible
to its wrapped type on reading, and providing an
assign function (operator =) for writing.

The following snippet illustrates the idea:

#include <iostream>
#include <map>
#include <string>

// a model of the store on the remote end
std::map<std::string, intstore;

// the call to the remote store sets a value
void set(std::string key, int val)
{
store[key] = val;
}

// this call to the remote store reads a value
int get(std::string key)
{
return store[key];
}

// the template wraps a native type
template<class T>
class remote_lval
{
public:
remote_lval(std::string key)
: key_(key)
{}

operator T()
{
return get(key_);
}

T operator = (T val)
{
set(key_, val);
return val;
}

private:
const std::string key_;
};

int main
(
int argc
, char* argv[]
)
{
remote_lval<intfoo("foo");
int bar;
int baz;
remote_lval<intfoobar("foobar");
remote_lval<int>& hmm(foobar);

foobar = baz = foo = bar = 42;

std::cout << foobar << ", " << baz << ", " << foo << ", " << bar <<
", " << hmm << std::endl;

foobar = foo + baz;

std::cout << foobar << ", " << baz << ", " << foo << ", " << bar <<
", " << hmm << std::endl;

return 0;
}

Altough the above code apparently works, I am not sure if I am
overseeing something important. I intend to extend the idea to
make the key_ a pos_type into a stream and be able to treat file
space like a memory space. I know that there will be issues of
caching and concurrency, but for the beginning I want to get the
lval wrapper right.

If anyone thinks what I am trying to do is a bad idea, I would be very
glad to learn the reasoning "why" it is a bad idea, before going
any further.

Thank you for your kind attention.

Roland aka. speedsnail

Jun 27 '08 #1
0 986

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: JKop | last post by:
When you want to store an integer in C++, you use an integral type, eg. int main() { unsigned char amount_legs_dog = 4; } In writing portable C++ code, there should be only two factors that...
388
by: maniac | last post by:
Hey guys, I'm new here, just a simple question. I'm learning to Program in C, and I was recommended a book called, "Mastering C Pointers", just asking if any of you have read it, and if it's...
30
by: josh | last post by:
Hi all, what does it meaning that strange sintax (look at the object :) ? if I have i.e. array.length I can use array. and is it IE/Firefox compatible??
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.