📊
Informatics Notes
  • About
  • About Programming Contests
  • Terminal Setup
  • Editor Setup
  • Debugging
  • Syntax and Templates
    • Scopes 101
    • Quickest IO Library
    • Writing Generic Code (Advanced Bronze)
    • Making a Contest Template
  • USACO Specific
    • Strategy for USACO Bronze
    • Preparing for Contests
    • USACO Division Ladders
    • Division Ladders Answers
  • Binary Lifting (Gold)
    • Binary Lifting (Gold) Intro
    • Binary Lifting (Gold) Part 1
    • Binary Lifting (Gold) Part 2
    • Binary Lifting (Gold) Part 3
  • Graphs (Silver)
  • Sweep Line
    • Sweep Line (Silver-Gold) Intro
    • Sweep Line (Silver-Gold) Part 1
  • Misc Tricks
    • Some C++ Contest Tricks I Wish I Were Told
    • Bitmasking: Generating Subsets Iteratively
    • Difference Arrays (Silver)
    • "Unusing" Identifiers
Powered by GitBook
On this page

Was this helpful?

  1. Misc Tricks

"Unusing" Identifiers

For background, consider the standard namespace. In competitive programming, frequent practice is

using namespace std; 

This is practical: we no longer need to prefix every identifier with std::. Terrible for production of course, but invaluable when time is of essence.

Of course, the reason this is considered bad practice is if you want to use something the std already predefines (especially an issue if you use bits). For instance

#include <bits/stdc++.h>
using namespace std; 

This code makes y1 unusable because it is already a symbol for a mathematical distribution in cmath. Naturally, one would want something like

#include <bits/stdc++.h>
using namespace std; 
not using std::y1; 

Unfortunately, however, this doesn't exist.

But there is a clever solution. In this case, we can literally use a find-and-replace solution to escape the y1 problem:

#include <bits/stdc++.h>
using namespace std; 
#define y1 _y1

Now, every y1 is replaced with _y1, which the compiler sees as nothing more than a variable name. This means that you can safely use y1 (while preprocessor will use the other version, a semantically safe alternative).

Alas, this extends and can be applied to anything one wants to "unuse" from the standard. For example, this gives you to opportunity to use "rank" instead of "rnk" in your functions.

PreviousDifference Arrays (Silver)

Last updated 3 years ago

Was this helpful?