On Wed, Dec 2, 2009 at 10:55 AM, James C. Sutherland
int main() { Properties p; int i=1; set(p,"int",i); set(p,"int*",&i);
int* j = get
(p,"int*"); // I don't want this to compile const int* k = get (p,"int*"); // I want this to compile fine. } Currently this whole code compiles without trouble, but I don't want to allow a non-const pointer to be extracted. Any ideas of how to accomplish this?
Thanks not possible AFAIK. The first compiles alright, but will fail at runtime because the boost::any was constructed using a const int*. By design all extractions are checked at runtime only, and the typeid()/std::type_info of what you put in and what you try to get it as must be the same. Given your code, you can't even do get<int>(p, "int"), because a const int was put in, not an int (see your set() impl), and typeid(int) != typeid(const int). --DD