aboutsummaryrefslogtreecommitdiff
path: root/bdep/new-types.ixx
blob: a8eafc5ceca4b5948f5227410ee1dc5755a6f83a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// file      : bdep/new-types.ixx -*- C++ -*-
// copyright : Copyright (c) 2014-2019 Code Synthesis Ltd
// license   : MIT; see accompanying LICENSE file

#include <bdep/utility.hxx> // move()

namespace bdep
{
  template <typename C, typename CXX>
  inline cmd_new_lang_template<C, CXX>::
  ~cmd_new_lang_template ()
  {
    if (lang == c)
      c_opt.~C ();
    else
      cxx_opt.~CXX ();
  }

  template <typename C, typename CXX>
  inline cmd_new_lang_template<C, CXX>::
  cmd_new_lang_template (cmd_new_lang_template&& l): lang (l.lang)
  {
    if (lang == c)
      new (&c_opt) C (move (l.c_opt));
    else
      new (&cxx_opt) CXX (move (l.cxx_opt));
  }

  template <typename C, typename CXX>
  inline cmd_new_lang_template<C, CXX>::
  cmd_new_lang_template (const cmd_new_lang_template& l): lang (l.lang)
  {
    if (lang == c)
      new (&c_opt) C (l.c_opt);
    else
      new (&cxx_opt) CXX (l.cxx_opt);
  }

  template <typename C, typename CXX>
  inline cmd_new_lang_template<C, CXX>& cmd_new_lang_template<C, CXX>::
  operator= (cmd_new_lang_template&& l)
  {
    if (this != &l)
    {
      this->~cmd_new_lang_template<C, CXX> ();

      // Assume noexcept move-construction.
      //
      new (this) cmd_new_lang_template<C, CXX> (move (l));
    }

    return *this;
  }

  template <typename C, typename CXX>
  inline cmd_new_lang_template<C, CXX>& cmd_new_lang_template<C, CXX>::
  operator= (const cmd_new_lang_template& l)
  {
    if (this != &l)
      *this = cmd_new_lang_template<C, CXX> (l); // Reduce to move-assignment.

    return *this;
  }
}