title: How to invoke descructor of static array in C++ template?
body: <p>How can the following template function be implemented in C++11 in order to support array types as a template parameter? Currently compilation fails with the error as below. Is there some syntactic trick that works this around?</p>
  
  <pre><code>template&lt;typename T&gt;
  void destroy(T &amp;o) { o.~T(); }
  
  int main()
  {
      int x;
      char y[3];
      destroy(x);
      destroy(y);
  }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>$ g++ test.cpp
  test.cpp: In instantiation of ‘void destroy(T&amp;) [with T = char [3]]’:
  test.cpp:9:18:   required from here
  test.cpp:2:26: error: request for member ‘~char [3]’ in ‘o’, which is of non-class type ‘char [3]’
  </code></pre>
  
  <p>Update:
  if a buffer of wrappers like struct Storage { CharType value; } is used instead of CharType (i.e. Storage* instead of CharType*) then this could allow the destructor of the CharType = array be called via Storage::~Storage(). And this could work in the code that caused this question. However, the question remains: if it is allowed to invoke a destructor of a fixed-size array explicitly in C++ and if it is then how to do this?</p>