access list : list « List « C++

access list

#include <set>
#include <string>
#include <list>
#include <iostream>
#include <iterator>
using namespace std;

using std::set;
using std::string;
using std::list;

class AccessList
  AccessList() {}

  void addUser(const string& user);

  void removeUser(const string& user);

  bool isAllowed(const string& user) const;

  list<string> getAllUsers() const;

  set<string> mAllowed;

void AccessList::addUser(const string& user)

void AccessList::removeUser(const string& user)

bool AccessList::isAllowed(const string& user) const
  return (mAllowed.count(user) == 1);

list<string> AccessList::getAllUsers() const
  list<string> users;
  users.insert(users.end(), mAllowed.begin(), mAllowed.end());
  return (users);

int main(int argc, char** argv)
  AccessList fileX;


  if (fileX.isAllowed("A")) {
    cout << "nsolter has permissions\n";

  if (fileX.isAllowed("B")) {
    cout << "baduser has permissions\n";

  list<string> users = fileX.getAllUsers();
  for (list<string>::const_iterator it = users.begin();
       it != users.end(); ++it) {
    cout << *it << " ";
  cout << endl;

  return (0);

Related examples in the same category

1.Instantiating an STL List of Integers
2.Use generic list to create a list of chars
3.Use generic list to create list of strings
4.Store class objects in a listStore class objects in a list
5.Store class objects with overloaded operators in a list.
6.Use std::copy to print all elements in a list
7.Pass list to a function
8.Uses ostream_iterator and copy algorithm to output list elements
9.Add elements in a multiset to a list
10.Comparison Algorithms
11.Add elements in a set to a list
12.Merge two lists.Merge two lists.
13.Using the list as a container for double value