Directed flow of charged particles within idealized viscous hydrodynamics at energies available at the BNL Relativistic Heavy Ion Collider and at the CERN Large Hadron Collider