Skip to content

Commit

Permalink
Use 'auto' for return types
Browse files Browse the repository at this point in the history
Might as well leverage the ability to deduce types. This technique also
found a bug for me where I was using the wrong type.
  • Loading branch information
bartecargo committed Nov 14, 2018
1 parent 97afcc8 commit 0e88c9d
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions sqlgrep/sqlgrep.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,25 @@ std::ostream& clear_eol(std::ostream& stream)
return stream;
}

void write_colour(string_view const message, std::ostream& colour(std::ostream& stream), std::ostream& background(std::ostream& stream), bool is_bold = false)
auto write_colour(string_view const message, std::ostream& colour(std::ostream& stream), std::ostream& background(std::ostream& stream), bool is_bold = false)
{
cout << clear_eol << colour << background << (is_bold ? termcolor::bold : colour) << message << termcolor::reset << endl;
}

void write_colour(string_view const message, std::ostream& colour(std::ostream& stream))
auto write_colour(string_view const message, std::ostream& colour(std::ostream& stream))
{
cout << clear_eol << colour << message << termcolor::reset << endl;
}

void write_verbose(string_view const message)
auto write_verbose(string_view const message)
{
if (verbose_messages_enabled)
{
write_colour(message, termcolor::green);
}
}

void write_error(string_view const message)
auto write_error(string_view const message)
{
cerr << termcolor::red << message << termcolor::reset << endl;
}
Expand All @@ -64,7 +64,7 @@ class database_query_logger : public logger_impl
}
};

void write_progress(uint64_t total, uint64_t completed, chrono::duration<uint64_t, std::nano> time_taken_so_far)
auto write_progress(uint64_t total, uint64_t completed, chrono::duration<uint64_t, std::nano> time_taken_so_far)
{
uint64_t const nanoseconds_per_second = 1'000'000'000L;
uint64_t const seconds_so_far = time_taken_so_far.count() / nanoseconds_per_second;
Expand All @@ -77,12 +77,12 @@ void write_progress(uint64_t total, uint64_t completed, chrono::duration<uint64_
cout << "\r";
}

string enquote(string_view const val)
auto enquote(string_view const val)
{
return "\""s + string(val) + "\"";
}

uint64_t get_number_of_rows(session & sql, string_view const schema, string_view const table, string_view const column, unordered_map<string, uint64_t> & cache)
auto get_number_of_rows(session & sql, string_view const schema, string_view const table, string_view const column, unordered_map<string, uint64_t> & cache)
{
uint64_t count;
stringstream query;
Expand All @@ -100,7 +100,7 @@ uint64_t get_number_of_rows(session & sql, string_view const schema, string_view
return count;
}

vector<column_details> get_all_string_columns(session & sql)
auto get_all_string_columns(session & sql)
{
cout << "Scanning for string columns..." << endl;

Expand Down Expand Up @@ -128,15 +128,15 @@ vector<column_details> get_all_string_columns(session & sql)
return details;
}

string escape_search_text(string_view to_find)
auto escape_search_text(string_view to_find)
{
regex const r("([\\\\%_[])");
string result;
regex_replace(back_inserter(result), begin(to_find), end(to_find), r, "\\$1");
return result;
}

vector<string> find_matches(session & sql, string_view const schema, string_view const table, string_view const column, string_view const to_find, int const maximum_results_per_column)
auto find_matches(session & sql, string_view const schema, string_view const table, string_view const column, string_view const to_find, int const maximum_results_per_column)
{
int const max_string = 500;
vector<string> matches(maximum_results_per_column + 1);
Expand All @@ -151,7 +151,7 @@ vector<string> find_matches(session & sql, string_view const schema, string_view
return matches;
}

void display_all_matches(session & sql, vector<column_details> const & all_columns, string_view to_find, int const maximum_results_per_column, uint64_t total_rows)
auto display_all_matches(session & sql, vector<column_details> const & all_columns, string_view to_find, int const maximum_results_per_column, uint64_t total_rows)
{
uint64_t completed_rows = 0;
auto const start_time = chrono::steady_clock::now();
Expand Down Expand Up @@ -187,7 +187,7 @@ void display_all_matches(session & sql, vector<column_details> const & all_colum
}
}

void find_and_display_matches(string_view to_find, int const maximum_results_per_column, string_view const connection_string)
auto find_and_display_matches(string_view to_find, int const maximum_results_per_column, string_view const connection_string)
{
connection_parameters parameters(odbc, string(connection_string));
parameters.set_option(odbc_option_driver_complete, to_string(SQL_DRIVER_NOPROMPT));
Expand All @@ -200,7 +200,7 @@ void find_and_display_matches(string_view to_find, int const maximum_results_per
display_all_matches(sql, all_columns, to_find, maximum_results_per_column, total_rows);
}

void configure_console_for_ansi_escape_sequences()
auto configure_console_for_ansi_escape_sequences()
{
auto const console_window = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD startup_console_mode;
Expand Down

0 comments on commit 0e88c9d

Please sign in to comment.