summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/filesystem/test/design_use_cases.cpp
blob: 49b0c28c0824f9234356d620a5c249aa50e2f99b (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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include <string>
#include <iostream>

//  Minimal class path

class path
{
public:
  path( const char * )
  {
    std::cout << "path( const char * )\n";
  }
  path( const std::string & )
  {
    std::cout << "path( std::string & )\n";
  }

//  for maximum efficiency, either signature must work
# ifdef BY_VALUE
  operator const std::string() const
# else
  operator const std::string&() const
# endif
  {
    std::cout << "operator string\n";
    return m_path;
  }

#ifdef NAMED_CONVERSION
  std::string string() const
  {
    std::cout << "std::string string() const\n";
    return m_path;
  }
#endif

private:
  std::string m_path;
};

bool operator==( const path &, const path & )
{
  std::cout << "operator==( const path &, const path & )\n";
  return true;
}

//  These are the critical use cases. If any of these don't compile, usability
//  is unacceptably degraded.

void f( const path & )
{
  std::cout << "f( const path & )\n";
}

int main()
{
  f( "foo" );
  f( std::string( "foo" ) );
  f( path( "foo" ) );

  std::cout << '\n';

  std::string s1( path( "foo" ) );
  std::string s2 = path( "foo" );
  s2 = path( "foo" );

#ifdef NAMED_CONVERSION
  s2 = path( "foo" ).string();
#endif

  std::cout << '\n';

  // these must call bool path( const path &, const path & );
  path( "foo" ) == path( "foo" );
  path( "foo" ) == "foo";
  path( "foo" ) == std::string( "foo" );
  "foo" == path( "foo" );
  std::string( "foo" ) == path( "foo" );

  return 0;
}