title: How to verify if a vector has a value at a certain index
body: <p>In a "self-avoiding random walk" situation, I have a 2-dimensional vector with a configuration of step-coordinates. I want to be able to check if a certain site has been occupied, but the problem is that the axis can be zero, so checking if the <code>fabs()</code> of the coordinate is <code>true</code> (or that it has a value), won't work. Therefore, I've considered looping through the steps and checking if my coordinate equals another coordinate on all axis, and if it does, stepping back and trying again (a so-called depth-first approach).</p>
  
  <p>Is there a more efficient way to do this? I've seen someone use a boolean array with all possible coordinates, like so:</p>
  
  <pre><code>bool occupied[nMax][nMax];          // true if lattice site is occupied
  for (int y = -rMax; y &lt;= rMax; y++)
          for (int x = -rMax; x &lt;= rMax; x++)
              occupied[index(y)][index(x)] = false;
  </code></pre>
  
  <p>But, in my program the number of dimensions is unknown, so would an approach such as:</p>
  
  <pre><code>typedef std::vector&lt;std::vector&lt;long int&gt;&gt; WalkVec;
  WalkVec walk(1, std::vector&lt;long int&gt;(dof,0));
  siteVisited = false; counter = 0;  
              while (counter &lt; (walkVec.back().size()-1))
              {
                  tdof = 1;
                  while (tdof &lt;= dimensions)
                  {
  
                      if (walkHist.back().at(tdof-1) == walkHist.at(counter).at(tdof-1) || walkHist.back().at(tdof-1) == 0)
                      {
                          siteVisited = true;
                      }
                      else
                      {
                          siteVisited = false;
                          break;
                      }
                      tdof++;
                  }
  </code></pre>
  
  <p>work where dof if the number of dimensions. (the check for zero checks if the position is the origin. Three zero coordinates, or three visited coordinates on the same step is the only way to make it true)
  Is there a more efficient way of doing it?</p>