I am writing a class based on memoir, which provides \tableofcontents (which lists the ToC within the ToC) and \tableofcontents* (which does not list the ToC within the ToC).
I have seen this question and its many duplicates, but I want to prevent the Table of Contents from itself being listed in the Table of Contents regardless of the user's choice of \tableofcontents* vs. \tableofcontents.
Based on the memoir manual (Section 9.2), I am currently using etoolbox to do
\pretocmd{\tableofcontents}{\begin{KeepFromToc}}{}{<class warning omitted>}
\apptocmd{\tableofcontents}{\end{KeepFromToc}}{}{<class warning omitted>}
which works as expected (both starred and unstarred variants do not write a ToC entry).
Is this a recommended way to do this? Does this method have any bad side effects I've not thought of?
Here is an MWE for any testing you may wish to do:
\documentclass{memoir}
\usepackage{etoolbox}
\pretocmd{\tableofcontents}{\begin{KeepFromToc}}{}{}
\apptocmd{\tableofcontents}{\end{KeepFromToc}}{}{}
\begin{document}
\tableofcontents
\chapter{Test Chapter}
\section{Test Section}
\end{document}