473,395 Members | 1,978 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,395 software developers and data experts.

recursive dereferencing library

I have a dereferencing template that I believe to be implemented
correctly and complete, but I would like to have it checked for
correctness to be sure. is this the right forum for such a thing?
Feb 20 '08 #1
5 1476
Sure, give it a whirl. At the bare minimum you'll get lots of good
advice about undefined gotchas and other weird stuff. As far actually
checking the syntax (not necessarily correctness of your
implementation), you can also try compiling your code with Comeau's
online compiler here:

http://www.comeaucomputing.com/tryitout/

Jason

"sebastian" <sm*******@yahoo.comwrote in message
news:
62**********************************...oglegroups.com...
>I have a dereferencing template that I believe to be implemented
correctly and complete, but I would like to have it checked for
correctness to be sure. is this the right forum for such a thing?
Feb 20 '08 #2
sebastian wrote:
I have a dereferencing template that I believe to be implemented
correctly and complete, but I would like to have it checked for
correctness to be sure. is this the right forum for such a thing?
If it's a question about the proper use of C++ then it is appropriate.
Feb 20 '08 #3
// extract.hpp

#ifndef XTD_EXTRACT_HPP
#define XTD_EXTRACT_HPP

namespace xtd {

/*
template to be specialized for user defined types
*/

template < typename Type >
struct content
{
typedef Type type;
typedef type & reference;

static inline
reference
extractor( reference object )
{
return object;
}
};

/*
user entry point
*/

template < typename Type >
inline
typename content< Type >::reference
extract( Type & object )
{
return content< Type >::extractor( object );
}

/*
specializations for references and pointers
*/

template < typename Type >
struct content< Type & >
{
typedef typename content< Type >::type type;
typedef type & reference;

static inline
reference
extractor( Type & object )
{
return extract( object );
}
};

template < typename Type >
struct content< Type * >
{
typedef typename content< Type >::type type;
typedef type & reference;

static inline
reference
extractor( Type * object )
{
return extract( *object );
}
};

template < typename Type >
struct content< Type * const >
{
typedef typename content< Type >::type type;
typedef type & reference;

static inline
reference
extractor( Type * const object )
{
return extract( *object );
}
};

/*
generic function object
*/

struct extractor
{
template < typename Type >
inline
typename content< Type >::reference
operator ( ) ( Type & object )
{
return extract( object );
}
};

} // namespace xtd

#endif // XTD_EXTRACT_HPP

// pointer_example.cpp

#include <iostream>
#include "extract.hpp"

using namespace std;
using namespace xtd;

int
main( void )
{
int
i = 1024,
* p = &i,
** pp = &p,
*** ppp = &pp;
extract( ppp )++;
cout << extract( ppp ) << endl;
return 0;
}

// auto_pointer_specialization_example.cpp

#include <iostream>
#include <memory>
#include "extract.hpp"

namespace xtd {

template < typename Type >
struct content< std::auto_ptr< Type
{
typedef typename content< Type >::type type;
typedef type & reference;

static inline
reference
extractor( std::auto_ptr< Type & object )
{
return extract( *object.get( ) );
}
};

template < typename Type >
struct content< std::auto_ptr< Type const >
{
typedef typename content< Type >::type type;
typedef type & reference;

static inline
reference
extractor( std::auto_ptr< Type const & object )
{
return extract( *object.get( ) );
}
};

} // namespace xtd

using namespace std;
using namespace xtd;

int
main( void )
{
auto_ptr< auto_ptr< int
ap( new auto_ptr< int >( new int( 1024 ) ) );
extract( ap )++;
cout << extract( ap ) << endl;
return 0;
}
Feb 21 '08 #4
sebastian wrote:
// extract.hpp
.... what problem are you trying to solve ?

It's very clever but I'm not sure it's really needed.
Feb 21 '08 #5
>... what problem are you trying to solve ?
the sole purpose of the library is to simplify complex dereferencing
accesses. also, it often allows the underlying storage of data to
change without necessarily changing the accessor code.
>but I'm not sure it's really needed.
its necessity or usefulness depends on the individual, I suppose.

Feb 22 '08 #6

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

Similar topics

4
by: Magnus Lie Hetland | last post by:
Hi! I've been looking at ways of dealing with nested structures in regexps (becuase I figured that would be faster than the Python parsing code I've currently got) and came across a few...
6
by: Johan Bergman | last post by:
Hi, Maybe someone can help me with this one. The following describes a somewhat simplified version of my problem, but I think it will be sufficient. I want to use class factories (virtual...
10
by: fabio de francesco | last post by:
Hi what do you think of the following? Why are we permitted to do that? And why the C++ Library doesn't stop someone willing to perfom that assignement (*a = 20)? #include <iostream> ...
51
by: BigMan | last post by:
Does the C++ standard define what should happen in case of NULL pointer dereferencing. If not, does it say that it is illegal? Where, if so, does it say it?
4
by: Piotr Filip Mieszkowski | last post by:
Hello, I like both C++ and Lisp and sometimes try to mix their ideas in the code I write. Recently I started to think about writing a pair class similar to the CONS in Lisp. (For those of you...
64
by: dmattis | last post by:
I am trying to write a recursive version of Power(x,n) that works by breaking n down into halves(where half of n=n/2), squaring Power(x,n/2), and multiplying by x again if n was odd, and to find a...
4
by: Pushkar Pradhan | last post by:
I have some functions which take as i/p a buffer (it can be float, char, or 16 bit, int etc.). The result is another o/p buffer, its type is also flexible (it could be a float, char etc.). I try...
5
by: purushneel | last post by:
Hi, I work primarily on Oracle databases. I am trying to convert a recursive stored procedure written in Oracle to DB2. Does DB2 UDB v8.2 (Windows/AIX) supports recursive stored procedures ??...
9
by: Csaba Gabor | last post by:
Inside a function, I'd like to know the call stack. By this I mean that I'd like to know the function that called this one, that one's caller and so on. So I thought to do: <script...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.