J
JKop
Having decided not to use macros at all in designing my reseatable
references, and having looked through the list of overloadable operators and
combinations of them, I've settled on the following syntax:
Reseat >> kref = moon;
Where "kref" is the reseatable reference and "moon" is the new object it'll
refer to.
Overall, once a reseatable reference has been defined, I want it to act
exactly as would a normal reference... but so far it doesn't seem like I'll
be able to achieve this, especially since I won't be able to access members
after the dot.
Anyway, to achieve the above syntax, I've declared a global object called
"Reseat" (sort of like "cout"). This "Reseat" global object is of type
"Reseat_Class". The "Reseat_Class" class has an operator>> defined which
returns by value an intialized object of type "RefReseater". The class
"RefReseater" is a friend of the "ReRef" and so has access to its "Reseat"
member function (not to be confused with the "Reseat" global object). The
"RefReseater" class has operator= defined which changes what's referred to.
Here's the code so far:
template<class T> class RefReseater;
template<class T>
class ReRef
{
private:
T* p_t;
ReRef& Reseat(T& in)
{
p_t = ∈
return *this;
}
public:
explicit ReRef() : p_t(0) {}
explicit ReRef(T& in)
{
Reseat(in);
}
/*
T& operator. ()
{
return *p_t;
}
*/
operator T&()
{
return *p_t;
}
friend class RefReseater<T>;
};
class Reseat_Class
{
public:
template<class T>
RefReseater<T> operator>> (ReRef<T>& in) const
{
return RefReseater<T>(in);
}
} Reseat;
template<class T>
class RefReseater
{
private:
ReRef<T>& reref_object;
public:
RefReseater(ReRef<T>& in) : reref_object(in)
{
}
ReRef<T>& operator= (T &object_in)
{
return reref_object.Reseat(object_in);
}
};
int main()
{
ReRef<int> j;
int a = 1;
int b = 2;
int c = 3;
int d = 4;
Reseat >> j = a;
//j = 9;
Reseat >> j = b;
//j = 8;
Reseat >> j = c;
//j = 7;
Reseat >> j = d;
//j = 6;
};
Any comments, questions, suggestions welcomed.
-JKop
references, and having looked through the list of overloadable operators and
combinations of them, I've settled on the following syntax:
Reseat >> kref = moon;
Where "kref" is the reseatable reference and "moon" is the new object it'll
refer to.
Overall, once a reseatable reference has been defined, I want it to act
exactly as would a normal reference... but so far it doesn't seem like I'll
be able to achieve this, especially since I won't be able to access members
after the dot.
Anyway, to achieve the above syntax, I've declared a global object called
"Reseat" (sort of like "cout"). This "Reseat" global object is of type
"Reseat_Class". The "Reseat_Class" class has an operator>> defined which
returns by value an intialized object of type "RefReseater". The class
"RefReseater" is a friend of the "ReRef" and so has access to its "Reseat"
member function (not to be confused with the "Reseat" global object). The
"RefReseater" class has operator= defined which changes what's referred to.
Here's the code so far:
template<class T> class RefReseater;
template<class T>
class ReRef
{
private:
T* p_t;
ReRef& Reseat(T& in)
{
p_t = ∈
return *this;
}
public:
explicit ReRef() : p_t(0) {}
explicit ReRef(T& in)
{
Reseat(in);
}
/*
T& operator. ()
{
return *p_t;
}
*/
operator T&()
{
return *p_t;
}
friend class RefReseater<T>;
};
class Reseat_Class
{
public:
template<class T>
RefReseater<T> operator>> (ReRef<T>& in) const
{
return RefReseater<T>(in);
}
} Reseat;
template<class T>
class RefReseater
{
private:
ReRef<T>& reref_object;
public:
RefReseater(ReRef<T>& in) : reref_object(in)
{
}
ReRef<T>& operator= (T &object_in)
{
return reref_object.Reseat(object_in);
}
};
int main()
{
ReRef<int> j;
int a = 1;
int b = 2;
int c = 3;
int d = 4;
Reseat >> j = a;
//j = 9;
Reseat >> j = b;
//j = 8;
Reseat >> j = c;
//j = 7;
Reseat >> j = d;
//j = 6;
};
Any comments, questions, suggestions welcomed.
-JKop