#include #include #include class textbox { // a class to handle a graphic text string // not fully implemented: public: // some kind of constructor? // change the text void settext(const string &text) { s = text; } void settext(string &&text) { s = std::move(text); } void settext(const char *text) { s = text; } // draw methods? // change font methods? // etc... private: string s; // other private fields }; class scatterplot { // a class to draw a scatter plot // not fully implemented: public: // some kind of constructor /* // to avoid set up costs (connecting to the display, etc) // this class provides a method to completely change the plot: void newplot(const string &title, const string &xlabel, const string &ylabel, const map points) { titlebox.settext(title); xaxisbox.settext(title); yaxisbox.settext(title); pts = points; // recalculate axis ticks, etc // call code to redraw } // but what if title, xlabel, ylabel, points are r-values? // to use above, they get converted to l-value refs and the // advantage is lost // Futhermore, we canot pass a const char * directly (although // type conversion will solve this). Perhaps "textbox" has a // faster implementation if a char * is passed in directly? // (same problem happens for constructors, frequently!) // or even simple setters (like "changetitle") that only pass along // one parameter/message. // we could try adding void newplot(string &&title, string &&xlabel, string &&ylabel, map &&points) { titlebox.settext(move(title)); xaxisbox.settext(move(title)); yaxisbox.settext(move(title)); pts = move(points); } // BUT, this only works if *all* of the arguments are r-val refs // (and it doesn't solve the char * problem!) // we'd really need to add 2^4=16 different versions, one for each // combination of rval and lval arguments. If we want to support // "char *" passing for the text args, we'd have to write // 3*3*3*2 different versions. // YUCK! // and, if textbox ever added a new "settext" that takes a new // type (like u32string), we'd have to change this again. */ // perfect forwarding solution: template void newplot(T1 &&title, T2 &&xlabel, T3 &&ylabel, T4 && points) { titlebox.settext(forward(title)); xaxisbox.settext(forward(title)); yaxisbox.settext(forward(title)); pts = forward(points); } private: textbox titlebox, xaxisbox, yaxisbox; map pts;