Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lots of code duplication in the line-reading exceptions #45

Closed
eyalroz opened this issue Jun 21, 2017 · 1 comment
Closed

Lots of code duplication in the line-reading exceptions #45

eyalroz opened this issue Jun 21, 2017 · 1 comment

Comments

@eyalroz
Copy link

eyalroz commented Jun 21, 2017

Example:

struct extra_column_in_header :
    base,
    with_file_name,
    with_column_name{
    void format_error_message()const{
                std::snprintf(error_message_buffer, sizeof(error_message_buffer),
                        "Extra column \"%s\" in header of file \"%s\"."
                        , column_name, file_name);
        }
};

struct missing_column_in_header :
        base,
        with_file_name,
        with_column_name{
        void format_error_message()const{
                std::snprintf(error_message_buffer, sizeof(error_message_buffer),
                        "Missing column \"%s\" in header of file \"%s\"."
                        , column_name, file_name);
        }
};

Essentially the same code but a different string. Considering how exceptions are, well, exceptional, I think it should not be impossible to get to something like:

using extra_column_in_header = exception<file_name, column_name>;
const char* exception_message_traits<extra_column_in_header>::format_string =
     "Extra column \"%s\" in header of file \"%s\".";
using missing_column_in_header  = exception<file_name, column_name>;
const char* exception_message_traits<missing_column_in_header >::format_string =
     "Missing column \"%s\" in header of file \"%s\".";

or whatever.

@ben-strasser
Copy link
Owner

Hi,

thanks for comment. However, I will not replace the comparatively easy to understand code with something that is only a few lines shorter and uses template-traits-voodoo. Without templates I do not see how one can shorten the code.

Best Regards
Ben Strasser

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants